db.models.ForeignKey.to_field

ForeignKey.to_field The field on the related object that the relation is to. By default, Django uses the primary key of the related object.

db.models.ForeignKey.swappable

ForeignKey.swappable Controls the migration framework’s reaction if this ForeignKey is pointing at a swappable model. If it is True - the default - then if the ForeignKey is pointing at a model which matches the current value of settings.AUTH_USER_MODEL (or another swappable model setting) the relationship will be stored in the migration using a reference to the setting, not to the model directly. You only want to override this to be False if you are sure your model should always point towar

db.models.ForeignKey.related_query_name

ForeignKey.related_query_name The name to use for the reverse filter name from the target model. It defaults to the value of related_name or default_related_name if set, otherwise it defaults to the name of the model: # Declare the ForeignKey with related_query_name class Tag(models.Model): article = models.ForeignKey( Article, on_delete=models.CASCADE, related_name="tags", related_query_name="tag", ) name = models.CharField(max_length=255) # That

db.models.ForeignKey.related_name

ForeignKey.related_name The name to use for the relation from the related object back to this one. It’s also the default value for related_query_name (the name to use for the reverse filter name from the target model). See the related objects documentation for a full explanation and example. Note that you must set this value when defining relations on abstract models; and when you do so some special syntax is available. If you’d prefer Django not to create a backwards relation, set related_n

db.models.ForeignKey.on_delete

ForeignKey.on_delete When an object referenced by a ForeignKey is deleted, Django will emulate the behavior of the SQL constraint specified by the on_delete argument. For example, if you have a nullable ForeignKey and you want it to be set null when the referenced object is deleted: user = models.ForeignKey( User, models.SET_NULL, blank=True, null=True, ) Deprecated since version 1.9: on_delete will become a required argument in Django 2.0. In older versions it defaults to

db.models.ForeignKey.limit_choices_to

ForeignKey.limit_choices_to Sets a limit to the available choices for this field when this field is rendered using a ModelForm or the admin (by default, all objects in the queryset are available to choose). Either a dictionary, a Q object, or a callable returning a dictionary or Q object can be used. For example: staff_member = models.ForeignKey( User, on_delete=models.CASCADE, limit_choices_to={'is_staff': True}, ) causes the corresponding field on the ModelForm to list only Us

db.models.ForeignKey.db_constraint

ForeignKey.db_constraint Controls whether or not a constraint should be created in the database for this foreign key. The default is True, and that’s almost certainly what you want; setting this to False can be very bad for data integrity. That said, here are some scenarios where you might want to do this: You have legacy data that is not valid. You’re sharding your database. If this is set to False, accessing a related object that doesn’t exist will raise its DoesNotExist exception.

db.models.ForeignKey

class ForeignKey(othermodel, on_delete, **options) [source] A many-to-one relationship. Requires a positional argument: the class to which the model is related. Changed in Django 1.9: on_delete can now be used as the second positional argument (previously it was typically only passed as a keyword argument). It will be a required argument in Django 2.0. To create a recursive relationship – an object that has a many-to-one relationship with itself – use models.ForeignKey('self', on_delete=mo

db.models.FloatField

class FloatField(**options) [source] A floating-point number represented in Python by a float instance. The default form widget for this field is a NumberInput when localize is False or TextInput otherwise. FloatField vs. DecimalField The FloatField class is sometimes mixed up with the DecimalField class. Although they both represent real numbers, they represent those numbers differently. FloatField uses Python’s float type internally, while DecimalField uses Python’s Decimal type. For info

db.models.FilePathField.recursive

FilePathField.recursive Optional. Either True or False. Default is False. Specifies whether all subdirectories of path should be included