Changes between Version 3 and Version 4 of new_meta_api


Ignore:
Timestamp:
Jul 11, 2014, 5:20:39 AM (10 years ago)
Author:
pirosb3
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • new_meta_api

    v3 v4  
    4141
    4242===== Related Object
    43 A Related Object is a relation from another model (such as a ForeignKey) that points to the current model
     43A Related Object is a one-to-many relation from another model (such as a ForeignKey) that points to the current model
    4444{{{
    4545class City(models.Model):
     
    5050    city = models.ForeignKey(City)
    5151}}}
    52      
     52In this case, City has a related object from Person (as you can access person_set)
    5353
    54 == Endpoints
     54===== Related M2M
     55A Related M2M is a M2M relation from another model that points to the current model
     56{{{
     57class City(models.Model):
     58    name = models.CharField(max_length=100)
    5559
     60class Person(models.Model):
     61    # M2M fields
     62    cities_lived_in = models.ManyToManyField(City)
     63}}}
     64 
     65In this case, City has a related m2m from Person
     66
     67===== Virtual
     68Virtual fields do not necessarily have an entry on the database, they are "Django fields" such as a GenericRelation
     69{{{
     70class Person(models.Model):
     71    content_type = models.ForeignKey(ContentType, related_name='+')
     72    object_id_ = models.PositiveIntegerField()
     73    item = GenericForeignKey('content_type', 'object_id')
     74}}}
     75GenericForeignKey uses content_type and object_id to keep track of what model type and id is set by item, but item itself does not have a concrete presence on the database.
     76In this case, item is a virtual field.
    5677
    5778
Back to Top