Unique fields that allow nulls in Django

Unique fields that allow nulls in Django

I have model Foo which has field bar. The bar field should be unique, but allow nulls in it, meaning I want to allow more than one record if bar field is null, but if it is not null the values must be…


python - Default value for field in Django model

Suppose I have a model: class SomeModel(models.Model): id=models.AutoField(primary_key=True) a=models.CharField(max_length=10) b=models.CharField(max_length=7) Currently I am using…


python - how do I use CommaSeparatedIntegerField in django?

There is almost no documentation for it here: http://docs.djangoproject.com/en/dev/ref/models/fields/#commaseparatedintegerfield Maybe someone could, by example, show me how to populate a CommaSeparat…


How do I get the default value for a field in a Django model?

I have a Django model with some fields that have default values specified. I am looking to grab the default value for one of these fields for us later on in my code. Is there an easy way to grab a p…



python - Django-Use of unicode

Why is a unicode function is required in models.py? i.e, def__unicode__(self) return sumid;…


How can I check if a URL exists with Django’s validators?

I want to check in django if a URL exists and if it does I want to show something on screen, i.e.: if URL_THAT_POINTS_TO_SOME_PDF exists SHOW_SOMETHING…


Django TextField max_length validation for ModelForm

Django does not respect the max_length attribute of TextField model field while validating a ModelForm. So I define a LimitedTextField inherited from the models.TextField and added validation bits si…


Django: Set field choices from view?

I've got some<selects> that I need to populate with some choices that depend on the currently logged in user. I don't think this is possible(or easy) to do from inside the form class, so can I just…


python - In Django models.py, what's the difference between default, null, and blank?

null=True blank=True default=0 What's the difference? When do you use what?…


python - Django: Non-ASCII character

My Django View/Template is not able to handle special characters. The simple view below fails because of the ñ. I get below error: Non-ASCII character '\xf1' in file" def test(request): return H…




charfield model field key foreign list default not models value