Django community: RSS
This page, updated regularly, aggregates Django Q&A from the Django community.
-
Using wysiwyg editor in the admin text area
I have bought a licence for the Redactor wysiwyg, and now I want to use it in my admin text area. I have got the javscript and css files to include. But I am not sure how to integrate the Redactor wysiwyg into the django admin text area. I have seen some other plugins also, but they are outdated versions, and I want to use the latest version. How can I use it in my admin? Your guidance will be very much appreciated. Thank you. -
django admin link to reverse relation object
i have following model class Invoice(models.Model): project = models.ForeignKey( Project, related_name = 'invoices' ) assume that already i have the Project model defined. now in Project model admin i want to add a link which will redirect me to the Invoice model detail page.I have already define admin for Invoice model too.Now i have written the following code in Project model's admin.py file. def invoice_link(self, obj): link = urlresolvers.reverse("admin:invoices_invoice_change", args=[ obj.invoices_set.all()[0].id]) return u'<a href="%s">%s</a>' % (link, obj.invoice.invoice_status) invoice_link.short_description = 'Generate Invoice' invoice_link.allow_tags = True but raising the followin error where i have used the obj.invoices_set.all()[0].id to get the id of related invoice object. i am definitely made a mistake here,but can't figure it out.How can i get the id of a reversely related object ? -
django- permission error when trying to create a file from another laptop served by apache2
enter image description here I have created a website in django and served it on apache2. It has a compiler which stores submissions on the admins laptop but when someone tries to submit it gives permission error. It works fine if I try to run locally without apache2. Please help. -
How to configure haystack for elasticsearch 5.0 in django settings?
I just upgraded elasticsearch to 5.0.0 . I have django 1.7.7 and djago-haystack 2.4.1 . In elasticsearch 5.0.0, Authorization header has been added for security purpose. So while making connection to elasticsearch through django, it's throwing error elasticsearch.exceptions.AuthenticationException: TransportError(401, u'security_exception') Where can we add the Authorization field in haystack configuration? -
Migrate existing Django users to OpenLDAP with the same password
I'm using Django's User model as the authentication backend. Now I want to migrate all the users to an OpenLDAP server. I believe if I can make OpenLDAP use the same hashing algorithm and password string format, I can just copy over the password hash from Django, users will just be able to login using the same username and password when I plug in OpenLDAP. My Django app's using PBKDF2 hasing algorithm so what I'm trying to do is to configure OpenLDAP to use PBKDF2 using this module: https://github.com/hamano/openldap-pbkdf2 The password hash in Django will be like: pbkdf2_sha256$12000$MySaltString$somehashstring... I tried many times but couldn't make it work with OpenLDAP. It would be great if you guys could give me some hints. Thanks a lot, Trinh -
Don't apply existing migrations for a model
I need to tell Django not to apply already existing migrations for a model. Is there a way I can achieve it? Why: I have some customizations on top of django.contrib.auth. With those, Group model is left unused. However, migrations for it are included into the auth app. Unlike User, Group is not swappable. -
get() returned more than one Children -- it returned 2! in django
I have a linked model: class Children(models.Model): person = models.ForeignKey(Person, on_delete=models.CASCADE) child_name = models.CharField(max_length=150, null=True, blank=True) slug = AutoSlugField(populate_from='child_name') blood_group = models.CharField(max_length=5, blank=True) class Meta: unique_together = ('slug', 'person') def get_absolute_url(self): return self.person.get_absolute_url() def get_delete_url(self): return reverse( 'member:children-delete', kwargs={ 'person_slug': self.person.slug, 'children_slug': self.slug}) def get_update_url(self): return reverse( 'member:children-update', kwargs={ 'person_slug': self.person.slug, 'children_slug': self.slug}) my forms.py: class ChildrenForm( SlugCleanMixin, forms.ModelForm): class Meta: model = Children exclude = ('person',) def clean(self): cleaned_data = super().clean() slug = cleaned_data.get('slug') person_obj = self.data.get('person') exists = ( Children.objects.filter( slug__iexact=slug, person=person_obj, ).exists()) if exists: raise ValidationError( "Children with this Slug " "and Person already exists.") else: return cleaned_data def save(self, **kwargs): instance = super().save(commit=False) instance.person = ( self.data.get('person')) instance.save() self.save_m2m() return instance views.py: class ChildrenCreate( ChildrenFormMixin, ChildrenGetObjectMixin, PersonContextMixin,CreateView): template_name = 'member/children_form.html' model = Children form_class = ChildrenForm class ChildrenUpdate(ChildrenFormMixin, ChildrenGetObjectMixin, PersonContextMixin,UpdateView): template_name = 'member/children_form.html' model = Children form_class = ChildrenForm slug_url_kwarg = 'children_slug' class ChildrenDelete(ChildrenFormMixin,ChildrenGetObjectMixin, PersonContextMixin,DeleteView): model = Children slug_url_kwarg = 'children_slug' def get_success_url(self): return (self.object.person .get_absolute_url()) my utils.py: class ChildrenFormMixin(): def get_form_kwargs(self): kwargs = super().get_form_kwargs() if self.request.method in ('POST', 'PUT'): self.person = get_object_or_404( Person, slug__iexact=self.kwargs.get( self.person_slug_url_kwarg)) data = kwargs['data'].copy() data.update({'person': self.person}) kwargs['data'] = data return kwargs class ChildrenGetObjectMixin(): def get_object(self, queryset=None): person_slug = self.kwargs.get( self.person_slug_url_kwarg) children_slug … -
Wagtail api add fields to pages endpoint
I have been trying to follow the following docs http://docs.wagtail.io/en/v1.6.3/reference/contrib/api/installation.html?highlight=api for my wagtail 1.6.3 instance. It tells me to add a field to the api_fields array in classes that extend page. So I have tried this: class HomePage(HeaderPage): body = RichTextField(blank=True) main_image = models.ForeignKey( 'wagtailimages.Image', null=True, blank=True, on_delete=models.SET_NULL, related_name='+' ) content_panels = HeaderPage.content_panels + [ FieldPanel('body', classname="full"), ImageChooserPanel('main_image') ] test = models.CharField(max_length=20, default="test"); api_fields = ['test', 'body', 'main_image','header_image', 'show_in_menus'] But I am only getting these fields on the detail page and on the /api/v1/pages/ endpoint it only shows the title and meta data field. How can I add more fields that will show on that enpoint -
Use ipdb with webapp2
I am django developer recently starting with webapp2 project. My question is how do I enter into debugging mode in webapp2 application using ipdb package as we do in django and flask. my app structure: helloapp - libs/ - stylesheets/ - templates/ - .gitignore - app.yaml - index.yaml - main.py - webapp2.py I have installed ipdb in libs folder using sudo pip install -t github_projects/hellowebapp2/libs ipdb main.py from .libs import ipdb class HelloWebapp2(webapp2.RedirectHandler): def get(self): import ipdb; ipdb.set_trace() Error /home/kishan/github_projects/hellowebapp2/main.py ERROR 2016-11-07 06:48:01,566 wsgi.py:263] Traceback (most recent call last): File "/usr/lib/google-cloud-sdk/platform/google_appengine/google/appengine/runtime/wsgi.py", line 240, in Handle handler = _config_handle.add_wsgi_middleware(self._LoadHandler()) File "/usr/lib/google-cloud-sdk/platform/google_appengine/google/appengine/runtime/wsgi.py", line 299, in _LoadHandler handler, path, err = LoadObject(self._handler) File "/usr/lib/google-cloud-sdk/platform/google_appengine/google/appengine/runtime/wsgi.py", line 85, in LoadObject obj = __import__(path[0]) File "/home/kishan/github_projects/hellowebapp2/main.py", line 12, in <module> from .libs import ipdb ValueError: Attempted relative import in non-package -
Send table data from template to view.py in django
I am passing a list i.e data_code from view.py to a html file and from there i am printing the data of the table using for loop through the list. There is a editable column in the table <input> and i want to get those data after filled by user on my view.py. so anybody any idea how to do that?? I want to get all {{x.2}} in view.py. It is printing some default value but i want it again after it is being by user. Here is the code: <table class="table table-bordered datatable"> <thead class="table-head"> <tr> <th>No</th> <th>Code Point</th> <th>Reference</th> <th>Character</th> <th>Text</th> <th>Description</th> </tr> </thead> <tbody> {% for x in data_code %} <tr class="table-row"> <td>{{ forloop.counter }}</td> <td><label>{{ x.0 }}</label></td> <td><input id="codepoint_input" type="text" value={{x.2}} size=3 title="Text"></td> <td><label> {{x.3}}</label></td> <td>{{x.4}}</td> </tr> {% endfor %} </tbody> </table> -
gaierror when trying to send email with Django using Google App Engine
I have deployed a Django project on Google App Engine and have set up django-password-reset in order for users to be able to reset their password through email verification. However, when I try to submit the recovery request I get this error: Environment: Request Method: POST Request URL: https://hrlite-143801.appspot.com/forgot-password/recover/ Django Version: 1.10.1 Python Version: 2.7.5 Installed Applications: ('django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'rest_framework', 'compressor', 'authentication', 'password_reset') Installed Middleware: ('django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.common.CommonMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.auth.middleware.SessionAuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware') Traceback: File "/base/data/home/apps/s~hrlite-143801/1.396880033573182710/lib/django/core/handlers/exception.py" in inner 39. response = get_response(request) File "/base/data/home/apps/s~hrlite-143801/1.396880033573182710/lib/django/core/handlers/base.py" in _legacy_get_response 249. response = self._get_response(request) File "/base/data/home/apps/s~hrlite-143801/1.396880033573182710/lib/django/core/handlers/base.py" in _get_response 187. response = self.process_exception_by_middleware(e, request) File "/base/data/home/apps/s~hrlite-143801/1.396880033573182710/lib/django/core/handlers/base.py" in _get_response 185. response = wrapped_callback(request, *callback_args, **callback_kwargs) File "/base/data/home/apps/s~hrlite-143801/1.396880033573182710/lib/django/views/generic/base.py" in view 68. return self.dispatch(request, *args, **kwargs) File "/base/data/home/apps/s~hrlite-143801/1.396880033573182710/lib/django/views/generic/base.py" in dispatch 88. return handler(request, *args, **kwargs) File "/base/data/home/apps/s~hrlite-143801/1.396880033573182710/lib/django/views/generic/edit.py" in post 183. return self.form_valid(form) File "/base/data/home/apps/s~hrlite-143801/1.396880033573182710/password_reset/views.py" in form_valid 100. self.send_notification() File "/base/data/home/apps/s~hrlite-143801/1.396880033573182710/password_reset/views.py" in send_notification 96. [self.user.email]) File "/base/data/home/apps/s~hrlite-143801/1.396880033573182710/lib/django/core/mail/__init__.py" in send_mail 62. return mail.send() File "/base/data/home/apps/s~hrlite-143801/1.396880033573182710/lib/django/core/mail/message.py" in send 342. return self.get_connection(fail_silently).send_messages([self]) File "/base/data/home/apps/s~hrlite-143801/1.396880033573182710/lib/django/core/mail/backends/smtp.py" in send_messages 100. new_conn_created = self.open() File "/base/data/home/apps/s~hrlite-143801/1.396880033573182710/lib/django/core/mail/backends/smtp.py" in open 58. self.connection = connection_class(self.host, self.port, **connection_params) File "/base/data/home/runtimes/python27/python27_dist/lib/python2.7/smtplib.py" in __init__ 250. (code, msg) = self.connect(host, port) File "/base/data/home/runtimes/python27/python27_dist/lib/python2.7/smtplib.py" in connect 310. self.sock = self._get_socket(host, port, … -
How to integrate BlurAdmin template with my django project?
Firstly, is it possible to integrate? If it is, can you let me know how to go about it. I am stuck here. I have cloned it to my system following the guidelines provided and it worked. Now I have to integrate this to my django project(Frontend -> AngularJS, Backend -> Python). So, it will be like mostly BlurAdmin for front-end and python for back-end. -
Make a view to update one element in a list in django
I am pretty new to django, I am displaying a list of items in my template and each item has an edit button, when user clicks it, an edit form pops up on the page. I am thinking to do this, on clicking edit, a js function is called that hides the rest of the page and the edit form which was hidden till now is made visible, but my problem is I don't know how should that edit form get information about that item to fill the fields of the form. I can make an edit view that will return a form filled with the information, but how will I call it. Is there any other way except ajax, I tried using ajax, it is not working. -
Why is the database used by Django subqueries not sticky?
I have a concern with django subqueries using the django ORM. When we fetch a queryset or perform a DB operation, I have the option of bypassing all assumptions that django might make for the database that needs to be used by forcing usage of the specific database that I want. b_det = Book.objects.using('some_db').filter(book_name = 'Mark') The above disregards any database routers I might have set and goes straight to 'some_db'. But if my models approximately look like so :- class Author(models.Model): author_name=models.CharField(max_length=255) author_address=models.CharField(max_length=255) class Book(models.Model): book_name=models.CharField(max_length=255) author=models.ForeignKey(Author, null = True) And I fetch a QuerySet representing all books that are called Mark like so:- b_det = Book.objects.using('some_db').filter(book_name = 'Mark') Then later if somewhere in the code I trigger a subquery by doing something like:- if b_det: auth_address = b_det[0].author.author_address Then this does not make use of the original database 'some_db' that I had specified early on for the main query. This again goes through the routers and picks up (possibly) the incorrect database. Why does django do this. IMHO , if I had selected forced usage of database for the original query then even for the subquery the same database needs to be used. Why must the database routers … -
Should I start a new Django app with version 1.8?
I'm about to create a new custom Django app for my organization. (I'm a brand new Django developer; this will be my first one apart from the occasional "Hello world" I've done as a prototype.) I'm on a shared hosting provider, which indicates that for Django applications, we should use Django version 1.8 (even though 1.10 is the current version) because 1.8 is the last version that supports FastCGI. Am I setting myself up for having a worthless app a few years from now once 1.8 is no longer supported? Would one expect that by the time 1.8 is no longer supported, the shared web hosting world will have moved on to WSGI or some form of workaround? Or is that a fundamental impossibility? Will I find in a couple of years that I've developed an application that is unusable on the host I've produced it for? Alternatively, should I be considering some other development tool for the situation I'm in? I'm on a shared host, and I'll be doing a fairly vanilla web front end / database back end style setup. -
Python return data for last 30 days
I have this log file sample which i need to count entries for the last one month, three months and one year. Here are just some few lines of the log file 10/14/2015 10:04:25 AM Following file:<open file 'dirs/tmp/bundle_21241.dat.json', mode 'r' at 0x8b73498> has invalid json which is ignored 11/15/2015 10:42:53 PM Following file:<open file 'dirs/tmp/bundle_21241.dat.json', mode 'r' at 0xa314498> has invalid json which is ignored 10/21/2015 10:16:42 AM Following hmac:94e301ff67773de56194165451535ba223cd27588221363290fbfcb96d9d0539 with is already in database so dropping 11/21/2015 10:16:42 AM The data for the duplicate Hmac is : HF 13300100012015-06-15 19:11:47+0000+ 12.61 0.430 1686.00 10/21/2015 10:16:42 AM Following hmac:c35330404902c0b1bb5c6d0718407ea12b25a464433bd1e69152ccc0e0b89c9f with is already in database so dropping 10/17/2015 10:16:42 AM The data for the duplicate Hmac is : HF 13300100012015-06-15 19:30:21+0000+ 12.61 0.010 1686.00 10/11/2015 10:16:42 AM Following hmac:8df71a9f6b6f0a0adb48c052767045f37ec34fce9c002a1c0c5ebc38ed500bf8 with is already in database so dropping 10/15/2015 10:16:42 AM The data for the duplicate Hmac is : HF 13300100012015-06-15 19:45:40+0000+ 12.61 0.018 1686.00 12/21/2015 10:16:42 AM Following hmac:fda9f5756461a8bc2922c55e75a31cf4915e6b0d016ecb786666624a0f04a02f with is already in database so dropping 12/10/2015 10:16:42 AM The data for the duplicate Hmac is : HF 13300100012015-06-15 20:01:01+0000+ 12.60 0.048 1686.00 07/21/2015 10:16:42 AM Following hmac:84d9cdb2145b7c3e0fa2d099070b7bd291c652f30ca25c69240e33ebbd2b8677 with is already in database so dropping Here is my code from datetime … -
Django: using multiple models in one view
I have three models linked via a Foreign Keys (Guest, Item, Order(FK Item, FK Guest)). No I want to write a view that shows the Guests Details from the model and a table view listing all his Orders in status unpaid). The first part I did like this. But how can I get the orders in? @login_required def guest_detail(request, pk): guest = get_object_or_404(Guest, pk=pk) if request.method == "POST": form = RegisterGuestForm(request.POST, instance=guest) if form.is_valid(): guest = form.save(commit=False) guest.save() #post.published_date = timezone.now() return redirect('guest_detail', pk=guest.pk) else: form = RegisterGuestForm(instance=guest) context = {'form': form} return render(request, 'hotel/register_guest.html', context) The Order Model looks like this: class Order(models.Model): guest = models.ForeignKey('hotel.Guest', on_delete=models.CASCADE) amount = models.IntegerField(default=1) item = models.ForeignKey('hotel.Item', on_delete=models.CASCADE) price = models.IntegerField() is_paid = models.BooleanField(default=False) class Meta: ordering = ['guest'] def __str__(self): return "{} x {}".format(self.amount, self.item) -
Django-crispy-form: Make input field and button in one line
I'd like to set input field('우편번호') and button in same line using django-crispy-form 's helper. code Div( Div( HTML(""" <label for="id_address" class="control-label requiredField"> 주소 </label> """), Field( 'postal_code', placeholder='우편번호', autocomplete='off', id='postal-code', readonly=True, style="width:150px;" ), Button( 'find_address', '우편번호 찾기', ), Field( 'address', placeholder='도로명/지번 주소', readonly=True, autocomplete='off', id='address', ), Field( 'address_detail', placeholder='상세주소', autocomplete='off', id='address-detail', ), css_class="col-lg-12", ), css_class="row" ), I have used input-group class, display:inline-block, etc but it doesn't work. Need help. Thanks. -
Django Redis Cache Admin Interface
I implemented Redis Caching in my Django.. However, is there a Friendly User Interface to just check the cache values like in Django Admin? -
no such table: paypal_expresstransaction
Problem integrating paypal express in a django oscar store. Added 'paypal' to installed apps and wrote template with the following code: {% extends 'oscar/checkout/payment_details.html' %} {% load i18n %} {% block payment_details %} <div class="well"> <div class="sub-header"> <h3>{% trans "PayPal Express" %}</h3> </div> <p>{% trans "Click on the below icon to use Express Checkout but where the shipping address and method is already chosen on the merchant site." %}</p> <div style="overflow:auto"><a href="{% url 'paypal-direct-payment' %}" title="{% trans "Pay with PayPal" %}"><img src="https://www.paypal.com/en_US/i/logo/PayPal_mark_37x23.gif" align="left" style="margin-right:7px;"></a>&nbsp;</div> </div> {% endblock %} Upon clicking on the payment button I get this error: no such table: paypal_expresstransaction -
Trouble serializing a one to many relationship
I am having some trouble serializing a model that contains a foreign key. My models are UserProfile that contains data about the user, a model that contains a list of possible Events and a model that contains all events by all Users. I want to output json with a list of all UserEvents ordered by say, dateCompleted. When I try to serialize the UserEvents I get an error: AttributeError: 'UserEvent' object has no attribute 'UserProfile' #My Models class AllEvent(models.Model): name = models.TextField(max_length = 100) eventType = models.IntegerField() minAge = models.DecimalField(max_digits = 5, decimal_places = 2) maxAge = models.DecimalField(max_digits = 5, decimal_places = 2) def __str__(self): return self.name class UserProfile(models.Model): user = models.OneToOneField(User) allEvents = models.ManyToManyField(AllEvent, related_name = 'allEvents', through='UserEvent') birthDate = models.DateField() gender = models.IntegerField(default=0) def __str__(self): return '%s %s' % (self.user.first_name, self.user.last_name) class UserEvent(models.Model): userProfile = models.ForeignKey(UserProfile, on_delete=models.CASCADE, related_name ='userOfEvent') allEvent = models.ForeignKey(AllEvent, on_delete=models.CASCADE, null=True, blank=True, related_name ='eventOfUser') completed = models.IntegerField(default=0, null=True, blank=True) dateCompleted = models.DateField(null=True, blank=True) def __str__(self): return '%s: %s' % (self.userProfile, self.allEvent) #My Serializers class UserSerializer(serializers.ModelSerializer): class Meta: model = User fields = ('first_name', 'last_name', 'email', 'password') class UserProfileSerializer(serializers.ModelSerializer): allEvents = serializers.StringRelatedField(many=True) first_name = serializers.CharField(source = 'user.first_name') last_name = serializers.CharField(source = 'user.last_name') email = serializers.CharField(source = … -
Cannot fix TypeError: int() argument must be a string or a number, not 'datetime.datetime
models.py class Like(models.Model): #nick_name=models.CharField(max_length=10) post = models.ForeignKey(UserImages, related_name='liked_post',blank=True,null=True) user = models.ForeignKey(Profile, related_name='liker',blank=True,null=True) date_created = models.DateTimeField(auto_now_add=True) Now I can't run manage.py migrate. Please Help. Very Urgent. Thanks -
Django: trying to pass users first name to template but getting a weird code instead
In views.py I have: def loggedin(request): return render_to_response('theDB/loggedin.html', {'first_name': User.first_name }) In loggedin.html I have: Hi {{ first_name }} you are now logged in! Click here to logout." This is what I get in the browser: Hi "<"django.db.models.query_utils.DeferredAttribute object at 0x0000019FD7AA7AC8> you are now logged in! Click here to logout. Instead of seeing the user's first name, I see that weird thing (a unicode object?) Thanks everyone! -
Nesting ViewSet routes in DRF
I've created 2 ModelViewSets like so (simplified for demonstration): class SomeBaseViewSet(viewsets.ReadOnlyModelViewSet): serializer_class = SomeEventSerializer permission_classes = (permissions.IsAuthenticated,) def get_queryset(self): return SomeObjects.objects.filter(owner=self.request.user) def get_serializer_context(self): context = super(SomeBaseViewSet, self).get_serializer_context() context.update({ "user": self.request.user, "some_context_key": False }) return context class AdminViewSet(SomeBaseViewSet): # Added in the HasAdminPermission permission_classes = (permissions.IsAuthenticated, HasAdminPermission) # Different queryset filter (overriding `get_queryset` vs setting queryset for standardization) def get_queryset(self): return SomeObjects.objects.all() # The context should have `some_context_key=True`, and `user=request.user` def get_serializer_context(self): context = super(AdminViewSet, self).get_serializer_context() context.update({ "some_context_key": True }) return context My router/url config looks like this router = DefaultRouter() router.register(r'some_view', SomeBaseViewSet, base_name="some_view") urlpatterns += [ url(r'^api/', include(router.urls)), ] If I wanted to route /api/some_view/admin to the AdminViewSet, what's the best way to do that? Things I've tried: @list_route on SomeBaseViewSet, but couldn't figure out the "right" way to wire it to my AdminViewSet Adding url(r'^api/some_view/admin$', AdminViewSet.as_view({"get": "list"})) to my urlpatterns (which sorta works but neuters the ViewSet a bit, and is generally really manual anyway): Having a dedicated DefaultRouter for the some_view viewset, which I then mount on url(r'^api/some_view/') - again hacky and pedantic to do with a large number of routes Is there a "right" way to do what I'm trying to accomplish, or should I reach for … -
Django Many-to-many with extra data
I've read through the the django page on many-to-many relationships, but can't figure out the right way to represent my ERD. I have a table (model) of instruments, and a table (model)of methods (representing work in a real-world laboratory). these need to have a many-to-many relationship, which Django would handle just fine via their models.ManyToManyField attribute. however, I must record a user (model is userProfile which is the validating_user for that relationship, and the timestamp of the validation. I could do it something like this: class Version(models.Model): version_number = models.CharField(max_length=50) cmd_line_script = models.CharField(max_length=250, null=False) SOP = models.TextField(null=False) FK_method = models.ForeignKey(Method, on_delete=models.CASCADE) class Meta: unique_together = ('version_number', 'FK_method') class Instrument(models.Model): serial_number = models.CharField(max_length=50, unique=True) asset_number = models.CharField(max_length=50, unique=True) name = models.CharField(max_length=50) checksum = models.BinaryField FK_instr_type = models.ForeignKey(InstrType, on_delete=models.PROTECT) Instr_Version = models.ManyToManyField( Version, through='Instr_Version', related_name = 'Instr_Version', ) class Instr_Version(models.Model): FK_version = models.ForeignKey(Version, on_delete=models.CASCADE) FK_instrument = models.ForeignKey(Instrument, on_delete=models.CASCADE) validating_user = models.ForeignKey(UserProfile, on_delete=models.PROTECT) timestamp = models.DateField(auto_now_add=True) class Meta: unique_together = ('FK_version', 'FK_instrument') which would look pretty much like a normal SQL setup, but I figure I should try to use the relationships in the most Django way possible. this is particularly relevant as I'm trying so set up serializers via the dangoRestFramework, and …