Django-polymodels. ¼øÀ§ ¹× ¿ä¾à
- ƯÇã:
- MIT/X Consortium Lic...
- °Ô½ÃÀÚ À̸§:
- Simon Charette
- °Ô½ÃÀÚ À¥»çÀÌÆ®:
- https://github.com/charettes/
Django-polymodels. ű×
Django-polymodels. ¼³¸í
Django-Polymodels´Â ¿ø·¡ ContentType.InstallationPIP ¼³Ä¡ Polymodelsmake¸¦`` 'django.contrib.contenttypes'¿Í`` '' '' ''polymodels '¸¦``installed_apps¿¡ ÀÖ´ÂÁö È®ÀÎÇÏ´Â °£´ÜÇÑ ¹æ¹ýÀ» Á¦°øÇÏ´Â °£´ÜÇÑ ¹æ¹ýÀ» Á¦°øÇÏ´Â Django ¾ÛÀÔ´Ï´Ù. `:: installation_apps + = ( 'django.contrib.contenttypes', 'polymodels') UsageYou ÇÏÀ§ Ŭ·¡½º``polymorphicmodel``´Â Ãß»óÀû ÀÎ ¸ðµ¨ Ŭ·¡½º - _models :::¿¡¼ django.db¿¡¼ polymodels.models °¡Á® ¿À±â ¸ðµ¨ polymorphicmodel Ŭ·¡½º µ¿¹° (polymorphicmodel) : name = models.charfield (max_length = 255) def __unicode __ (self) : return self.name Ŭ·¡½º Æ÷À¯·ù (µ¿¹°) : Æнº Ŭ·¡½º °³ (Æ÷À¯·ù) : Æнº Ŭ·¡½º ÆÄÃæ·ù (µ¿¹°) : Æнº Ŭ·¡½º ¹ì (Reptile) : Class Meta : Proxy = TrueObjects´Â Æò¼Ò¿Í µ¿ÀÏÇÑ ¹æ½ÄÀ¸·Î ¸¸µé¾îÁö°í ¿¬°üµÈ``ContentType``°¡ ÀÚµ¿À¸·Î ÀúÀåµË´Ï´Ù. >>> µ¿¹° = animal.objects.create (À̸§ = 'µ¿¹°') >>> Æ÷À¯·ù = mammal.objects.create (name = 'Æ÷À¯·ù') >>> reptile = reptile.objects.create (name = 'fretile') >>> snake = snake.objects.create (n ame = 'snake'```animal.objects``manager¿¡¼``select_subclasses`` ¸Þ¼Òµå¸¦ »ç¿ëÇؾ߸¸ÇÑ```select_subclasss.select_subclasses () ``select_subclass`` : >>> animal.objects.select_subclasses (ÆÄÃæ·ù) ¶Ç´Â ¼ºê Ŭ·¡½º °ü¸®ÀÚ¿¡¼ Á÷Á¢ : >>> reptile.Objects.Select_Subclasses (¹ì) ¿ø·¡ÀÇ °á°ú¸¦ ``select_subclasses`` "animal.objects.select_subclassess.select_subclasses () ``polymorphicmodel`` ½º½º·Î¸¦ ¿Ã¹Ù¸¥``coltertype``·Î º¯È¯ÇÏ´Â ¹æ¹ýÀ» ¾Ë°íÀÖ´Â``type_cast``. >>> animal_snake = animal.objects.get (pk = snake.pk) <µ¿¹° : ¹ì>>>> animal_snake. type_cast () <¹ì : ¹ì>>>> µ¿¹° _snake.t. ype_cast (ÆÄÃæ·ù) ``polymorphicmodel.content_type`` Çʵ尡 ±âÁ¸ Çʵå Áß Çϳª¿Í Ãæµ¹Çϸé``polymodels.models.basepolymorphicmodel``À» ÇÏÀ§ Ŭ·¡½º¿¡ Æ÷ÇÔ½ÃÅ°´Â °æ¿ì. ¸ðµ¨¿¡ ´ëÇÑ``content_type_field_name'`` ¼Ó¼ºÀ» Á¤ÀÇÇÏ¿© ¾î¶² Çʵ带 »ç¿ëÇØ¾ß ÇÏ´ÂÁö¸¦ ³ªÅ¸³»´Â °ÍÀ» ÀØÁö ¸¶½Ê½Ã¿À. ÀÌ Çʵå´Â``countertype`` : django.contrib.contenttypes.models¿¡¼ contentType¿¡¼ polymodels.models °¡Á® ¿À±â basepolymorphicmodel class myModel (basepolymorphicmodel) °¡Á® ¿À±â : content_type_field_name = 'polymorphic_ct 'Polymorphic_CT = ¸ðµ¨. ForeignKey (ContentType) Á¦Ç°ÀÇ È¨ÆäÀÌÁö
Django-polymodels. °ü·Ã ¼ÒÇÁÆ®¿þ¾î