Linked Questions
21 questions linked to/from How to define two fields "unique" as couple
0 votes
1 answer
427 views
Django model prevent Duplicate based on two variables [duplicate]
I need to make sure the entry does not have the same project and case id. How is the best way to prevent a duplicate entry? Here the project can not have the same case twice. class Cases(models....
0 votes
1 answer
91 views
Unique DB entry to the user [duplicate]
I have a model that takes in a listname. I only want the list name to disable duplicates per user. Currently, a user cannot enter "recipes" twice, but if another user doesn't have a "...
2 votes
2 answers
1k views
How to add a "unique_together" constraint to a core model in django?
I'm trying to extend the django Group model to make it friendlier for multi tenancy. Basically I want to remove the unique constraint on the name field, add a field called tenant, and make name and ...
3 votes
2 answers
386 views
Django: Constraint on multiple model fields
Example: class Author(models.Model): first_name = models.CharField() last_name = models.CharField() def _get_full_name(self): return '{0} {1}'.format(self.first_name, self....
0 votes
2 answers
186 views
2 fields unique
I have this model: class blog(models.Model): user = models.ForeignKey(User) mail = models.EmailField(max_length=60, null=False, blank=False) name = models.CharField(max_length=60, blank=...
2 votes
2 answers
718 views
Is possible to make unique a field in the database for a foreign key?
Lets suppose that I have two models named Company and Airplane: class Company(models.Model): name= models.CharField(max_length=250) location=models.Charfield(max_length=250) class Airplane(...
0 votes
1 answer
839 views
Django. How to restrict a user to put review only once?
Hello guys I am making a ecommerce website as part of learning django. I have a review model but I want to make sure that a customer can only put a review once. How to do that with my existing model ...
0 votes
1 answer
1k views
Django Rest Framework IntegrityError when tried use unique_together
This question seems to be similar to what I am aiming for but I get an error IntegrityError column username_id is not unique What I am looking for is having these fields be unique only when together. ...
0 votes
1 answer
578 views
Need two fields together to be unique
Say I have a model like this: class Book(models.Model): user = models.ForeignKey(User) book_isbn = models.CharField() I would like the combination of the book and user fields to be unique. ...
0 votes
2 answers
368 views
Django REST validator. Multiple users can have records with same value, but that record is unique for each user, how to do that?
I am trying to accomplish the following with Django REST framework. I have model Records, which has field. It has foreign key to User. Each user can create multiple records with different numbers, ...
0 votes
2 answers
338 views
Django Models how to add unique constraint
Unsimilar to for example this case I am trying to allow only one entry in a database for one user: class Station(models.Model): serial = models.CharField("serial", max_length = 31, ...
0 votes
1 answer
490 views
How to create a relation to intermediate table using Model in Django?
Could anyone help me create this database using the ORM model in Django? I'm stuck at creating a relation between the ATTENDANCE and CLASSDETAIL table. Please look at this ERD:
1 vote
0 answers
473 views
How to put a constraint using foreign key fields in Django?
Consider following models: class Model1: x = an integer y = an integer class Model2: f1 = models.ForeignKey(Model1) f2 = models.ForeignKey(Model1) Now, I want to put a constraint on ...
1 vote
1 answer
229 views
How can I make a Model field value unique (unique=True) but only comparing it to other models from that User?
I have a Tag model, that must have a name field that needs to be unique, but only for that user's tags. So that one user can't create two 'tagname' tags, but many different users can (create a tag ...
0 votes
1 answer
98 views
Django model ensuring two properties should always be different - Is unique_together the answer?
How do I ensure that a unique combination of two properties should not be repeated For instance in the following model class modelBodyPart(models.Model): area = models.CharField(max_length=128) ...