Case insensitive unique model fields in Django?

As of Django 1.11, you can use CITextField, a Postgres-specific Field for case-insensitive text backed by the citext type. from django.db import models from django.contrib.postgres.fields import CITextField class Something(models.Model): foo = CITextField() Django also provides CIEmailField and CICharField, which are case-insensitive versions of EmailField and CharField.

Populating django field with pre_save()?

Most likely you are referring to django’s pre_save signal. You could setup something like this: from django.db.models.signals import pre_save from django.dispatch import receiver from django.template.defaultfilters import slugify @receiver(pre_save) def my_callback(sender, instance, *args, **kwargs): instance.slug = slugify(instance.title) If you dont include the sender argument in the decorator, like @receiver(pre_save, sender=MyModel), the callback will be called for … Read more

DDD and MVC: Difference between ‘Model’ and ‘Entity’

Entity Entity means an object that is a single item that the business logic works with, more specifically those which have an identity of some sort. Thus, many people refer to ORM-mapped objects as entities. Some refer to as “entity” to a class an instance of which represents a single row in a database. Some … Read more

How can I set two primary key fields for my models in Django?

Update Django 4.0 Django 4.0 documentation recommends using UniqueConstraint with the constraints option instead of unique_together. Use UniqueConstraint with the constraints option instead. UniqueConstraint provides more functionality than unique_together. unique_together may be deprecated in the future. class Hop(models.Model): migration = models.ForeignKey(‘Migration’) host = models.ForeignKey(User, related_name=”host_set”) class Meta: constraints = [ models.UniqueConstraint( fields=[‘migration’, ‘host’], name=”unique_migration_host_combination” ) … Read more

ForeignKey does not allow null values

The blank option is used in the form validation, and the null is used when writing to database. So you might add null=True to that field. EDIT: continue the comment Considering the two steps when saving object: Validator(controlled by blank) Database limitation(controlled by null) For default option, take IntegerField for example, default=5, blank=True, null=False, pass … Read more

Should I make a DateRange object?

No, you didn’t miss a general purpose class. I have a Range type in MiscUtil which you may be interested in – and it certainly makes for simple DateTime manipulation. Referring to Marc’s answer, I can’t remember whether this is a struct or a class – you’d be welcome to change it of course. It’s … Read more

Differentiating between domain, model, and entity with respect to MVC

The terms are a bit vague I agree. I would use domain to refer to the business area you are dealing with. Like banking or insurance or what not. Then you have domain models. These are the things you deal with in that business domain, like for domain of banking you have accounts, customers, transfers … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)