Ticket #12168: django_model_package_test.patch
File django_model_package_test.patch, 2.3 KB (added by , 15 years ago) |
---|
-
django/tests/modeltests/model_package/__init__.py
1 -
django/tests/modeltests/model_package/models/publication.py
1 2 3 from django.db import models 4 5 6 class Publication(models.Model): 7 title = models.CharField(max_length=30) 8 9 class Meta: 10 app_label = 'model_package' -
django/tests/modeltests/model_package/models/__init__.py
1 2 from publication import Publication 3 from article import Article 4 from django.contrib.auth.views import Site 5 6 __test__ = {'API_TESTS': """ 7 >>> p = Publication(title="FooBar") 8 >>> p.save() 9 >>> p 10 <Publication: Publication object> 11 12 >>> from django.contrib.sites.models import Site 13 >>> current_site = Site.objects.get_current() 14 >>> current_site 15 <Site: example.com> 16 17 M2M doesn't work, because the M2M tables doesn't created if models is a package. 18 19 >>> a = Article(headline="a foo headline") 20 >>> a.save() 21 >>> a.publications.add(p) 22 >>> a.sites.add(current_site) 23 >>> a.save() 24 25 26 >>> a = Article.objects.get(id=1) 27 >>> a 28 <Article: Article object> 29 >>> a.id 30 1 31 >>> a.sites.count() 32 """} -
django/tests/modeltests/model_package/models/article.py
1 2 3 from django.db import models 4 from django.contrib.sites.models import Site 5 6 class Article(models.Model): 7 sites = models.ManyToManyField(Site) 8 headline = models.CharField(max_length=100) 9 publications = models.ManyToManyField("model_package.Publication", null=True, blank=True,) 10 11 class Meta: 12 app_label = 'model_package'