Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

django unique field

is there another REGEX way (or another way) to ensure that a model class field would be unique? (it is not a key, or at least not declared as a key, is shoulb be a simple CharField)

Thanks

like image 264
dana Avatar asked Jul 03 '10 19:07

dana


People also ask

How do you make sure a field is unique in Django?

Of course, you should have an id tag, which is always unique, because it's a primary key. However, certain fields may also need to be unique, because certain fields may need to be unique without any repetition. So, to make a field unique in Django is very basic. You just set the unique attribute to true.

What is App_label in Django?

app_label is used when you have models in a place in which django doesn't know to which app they belong.

What is unique field in Django?

unique=True sets the field to be unique i.e. once entered a value in a field, the same value can not be entered in any other instance of that model in any manner. It is generally used for fields like Roll Number, Employee Id, etc which should be unique.

What is slug field in Django?

What is SlugField in Django? It is a way of generating a valid URL, generally using data already obtained. For instance, using the title of an article to generate a URL. Let's assume our blog have a post with the title 'The Django book by Geeksforgeeks' with primary key id= 2.


2 Answers

The normal way to make a single field unique is to use the unique argument to the field constructor.

like image 67
Ignacio Vazquez-Abrams Avatar answered Sep 18 '22 23:09

Ignacio Vazquez-Abrams


If you need to make this unique on more than one field, have a look at: unique-together

like image 33
IonicBurger Avatar answered Sep 21 '22 23:09

IonicBurger