Ticket #12168: django_model_package_test.patch

File django_model_package_test.patch, 2.3 KB (added by jedie, 15 years ago)

try to test a model package

  • django/tests/modeltests/model_package/__init__.py

     
     1
  • django/tests/modeltests/model_package/models/publication.py

     
     1
     2
     3from django.db import models
     4
     5
     6class 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
     2from publication import Publication
     3from article import Article
     4from 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
     17M2M 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
     301
     31>>> a.sites.count()
     32"""}
  • django/tests/modeltests/model_package/models/article.py

     
     1
     2
     3from django.db import models
     4from django.contrib.sites.models import Site
     5
     6class 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'
Back to Top