Changes between Version 3 and Version 4 of new_meta_api
- Timestamp:
- Jul 11, 2014, 5:20:39 AM (10 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
new_meta_api
v3 v4 41 41 42 42 ===== Related Object 43 A Related Object is a relation from another model (such as a ForeignKey) that points to the current model43 A Related Object is a one-to-many relation from another model (such as a ForeignKey) that points to the current model 44 44 {{{ 45 45 class City(models.Model): … … 50 50 city = models.ForeignKey(City) 51 51 }}} 52 52 In this case, City has a related object from Person (as you can access person_set) 53 53 54 == Endpoints 54 ===== Related M2M 55 A Related M2M is a M2M relation from another model that points to the current model 56 {{{ 57 class City(models.Model): 58 name = models.CharField(max_length=100) 55 59 60 class Person(models.Model): 61 # M2M fields 62 cities_lived_in = models.ManyToManyField(City) 63 }}} 64 65 In this case, City has a related m2m from Person 66 67 ===== Virtual 68 Virtual fields do not necessarily have an entry on the database, they are "Django fields" such as a GenericRelation 69 {{{ 70 class Person(models.Model): 71 content_type = models.ForeignKey(ContentType, related_name='+') 72 object_id_ = models.PositiveIntegerField() 73 item = GenericForeignKey('content_type', 'object_id') 74 }}} 75 GenericForeignKey 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. 76 In this case, item is a virtual field. 56 77 57 78