diff --git a/django/contrib/gis/tests/distapp/models.py b/django/contrib/gis/tests/distapp/models.py index 811c275faf..d10ce76158 100644 --- a/django/contrib/gis/tests/distapp/models.py +++ b/django/contrib/gis/tests/distapp/models.py @@ -3,77 +3,53 @@ from django.utils.encoding import python_2_unicode_compatible @python_2_unicode_compatible -class SouthTexasCity(models.Model): +class NamedModel(models.Model): + name = models.CharField(max_length=30) + + objects = models.GeoManager() + + class Meta: + abstract = True + app_label = 'distapp' + + def __str__(self): + return self.name + + +class SouthTexasCity(NamedModel): "City model on projected coordinate system for South Texas." - name = models.CharField(max_length=30) point = models.PointField(srid=32140) - objects = models.GeoManager() - - def __str__(self): - return self.name -@python_2_unicode_compatible -class SouthTexasCityFt(models.Model): +class SouthTexasCityFt(NamedModel): "Same City model as above, but U.S. survey feet are the units." - name = models.CharField(max_length=30) point = models.PointField(srid=2278) - objects = models.GeoManager() - - def __str__(self): - return self.name -@python_2_unicode_compatible -class AustraliaCity(models.Model): +class AustraliaCity(NamedModel): "City model for Australia, using WGS84." - name = models.CharField(max_length=30) point = models.PointField() - objects = models.GeoManager() - - def __str__(self): - return self.name -@python_2_unicode_compatible -class CensusZipcode(models.Model): +class CensusZipcode(NamedModel): "Model for a few South Texas ZIP codes (in original Census NAD83)." name = models.CharField(max_length=5) poly = models.PolygonField(srid=4269) - objects = models.GeoManager() - - def __str__(self): - return self.name -@python_2_unicode_compatible -class SouthTexasZipcode(models.Model): +class SouthTexasZipcode(NamedModel): "Model for a few South Texas ZIP codes." name = models.CharField(max_length=5) poly = models.PolygonField(srid=32140, null=True) - objects = models.GeoManager() - - def __str__(self): - return self.name -@python_2_unicode_compatible -class Interstate(models.Model): +class Interstate(NamedModel): "Geodetic model for U.S. Interstates." name = models.CharField(max_length=10) path = models.LineStringField() - objects = models.GeoManager() - - def __str__(self): - return self.name -@python_2_unicode_compatible -class SouthTexasInterstate(models.Model): +class SouthTexasInterstate(NamedModel): "Projected model for South Texas Interstates." name = models.CharField(max_length=10) - path = models.LineStringField(srid=32140) - objects = models.GeoManager() - def __str__(self): - return self.name diff --git a/django/contrib/gis/tests/geo3d/models.py b/django/contrib/gis/tests/geo3d/models.py index 023c71ead1..2244ed8b15 100644 --- a/django/contrib/gis/tests/geo3d/models.py +++ b/django/contrib/gis/tests/geo3d/models.py @@ -3,85 +3,63 @@ from django.utils.encoding import python_2_unicode_compatible @python_2_unicode_compatible -class City3D(models.Model): +class NamedModel(models.Model): name = models.CharField(max_length=30) - point = models.PointField(dim=3) + objects = models.GeoManager() + class Meta: + abstract = True + app_label = 'geo3d' + def __str__(self): return self.name -@python_2_unicode_compatible -class Interstate2D(models.Model): - name = models.CharField(max_length=30) +class City3D(NamedModel): + point = models.PointField(dim=3) + + +class Interstate2D(NamedModel): line = models.LineStringField(srid=4269) - objects = models.GeoManager() - - def __str__(self): - return self.name -@python_2_unicode_compatible -class Interstate3D(models.Model): - name = models.CharField(max_length=30) +class Interstate3D(NamedModel): line = models.LineStringField(dim=3, srid=4269) - objects = models.GeoManager() - - def __str__(self): - return self.name -@python_2_unicode_compatible -class InterstateProj2D(models.Model): - name = models.CharField(max_length=30) +class InterstateProj2D(NamedModel): line = models.LineStringField(srid=32140) - objects = models.GeoManager() - - def __str__(self): - return self.name -@python_2_unicode_compatible -class InterstateProj3D(models.Model): - name = models.CharField(max_length=30) +class InterstateProj3D(NamedModel): line = models.LineStringField(dim=3, srid=32140) - objects = models.GeoManager() - - def __str__(self): - return self.name -@python_2_unicode_compatible -class Polygon2D(models.Model): - name = models.CharField(max_length=30) +class Polygon2D(NamedModel): poly = models.PolygonField(srid=32140) - objects = models.GeoManager() - - def __str__(self): - return self.name -@python_2_unicode_compatible -class Polygon3D(models.Model): - name = models.CharField(max_length=30) +class Polygon3D(NamedModel): poly = models.PolygonField(dim=3, srid=32140) + + +class SimpleModel(models.Model): + objects = models.GeoManager() - def __str__(self): - return self.name + class Meta: + abstract = True + app_label = 'geo3d' -class Point2D(models.Model): +class Point2D(SimpleModel): point = models.PointField() - objects = models.GeoManager() -class Point3D(models.Model): +class Point3D(SimpleModel): point = models.PointField(dim=3) - objects = models.GeoManager() -class MultiPoint3D(models.Model): +class MultiPoint3D(SimpleModel): mpoint = models.MultiPointField(dim=3) - objects = models.GeoManager() diff --git a/django/contrib/gis/tests/geoadmin/models.py b/django/contrib/gis/tests/geoadmin/models.py index d1d671954a..381a752570 100644 --- a/django/contrib/gis/tests/geoadmin/models.py +++ b/django/contrib/gis/tests/geoadmin/models.py @@ -7,8 +7,12 @@ from django.utils.encoding import python_2_unicode_compatible class City(models.Model): name = models.CharField(max_length=30) point = models.PointField() + objects = models.GeoManager() + class Meta: + app_label = 'geoadmin' + def __str__(self): return self.name diff --git a/django/contrib/gis/tests/geoapp/models.py b/django/contrib/gis/tests/geoapp/models.py index 8234bc8d9b..3e1e927155 100644 --- a/django/contrib/gis/tests/geoapp/models.py +++ b/django/contrib/gis/tests/geoapp/models.py @@ -7,66 +7,66 @@ null_flag = not mysql @python_2_unicode_compatible -class Country(models.Model): +class NamedModel(models.Model): name = models.CharField(max_length=30) + + objects = models.GeoManager() + + class Meta: + abstract = True + app_label = 'geoapp' + + def __str__(self): + return self.name + +class Country(NamedModel): mpoly = models.MultiPolygonField() # SRID, by default, is 4326 - objects = models.GeoManager() - - def __str__(self): - return self.name -@python_2_unicode_compatible -class City(models.Model): - name = models.CharField(max_length=30) +class City(NamedModel): point = models.PointField() - objects = models.GeoManager() - - def __str__(self): - return self.name # This is an inherited model from City class PennsylvaniaCity(City): county = models.CharField(max_length=30) founded = models.DateTimeField(null=True) - objects = models.GeoManager() # TODO: This should be implicitly inherited. + + # TODO: This should be implicitly inherited. + + objects = models.GeoManager() + + class Meta: + app_label = 'geoapp' -@python_2_unicode_compatible -class State(models.Model): - name = models.CharField(max_length=30) +class State(NamedModel): poly = models.PolygonField(null=null_flag) # Allowing NULL geometries here. - objects = models.GeoManager() - - def __str__(self): - return self.name -@python_2_unicode_compatible -class Track(models.Model): - name = models.CharField(max_length=30) +class Track(NamedModel): line = models.LineStringField() - objects = models.GeoManager() - - def __str__(self): - return self.name class Truth(models.Model): val = models.BooleanField(default=False) + objects = models.GeoManager() -if not spatialite: - @python_2_unicode_compatible - class Feature(models.Model): - name = models.CharField(max_length=20) - geom = models.GeometryField() - objects = models.GeoManager() + class Meta: + app_label = 'geoapp' + + +if not spatialite: + + class Feature(NamedModel): + geom = models.GeometryField() - def __str__(self): - return self.name class MinusOneSRID(models.Model): geom = models.PointField(srid=-1) # Minus one SRID. + objects = models.GeoManager() + + class Meta: + app_label = 'geoapp' diff --git a/django/contrib/gis/tests/geogapp/models.py b/django/contrib/gis/tests/geogapp/models.py index 1953bc5a29..ce637c38a5 100644 --- a/django/contrib/gis/tests/geogapp/models.py +++ b/django/contrib/gis/tests/geogapp/models.py @@ -3,31 +3,30 @@ from django.utils.encoding import python_2_unicode_compatible @python_2_unicode_compatible -class City(models.Model): +class NamedModel(models.Model): name = models.CharField(max_length=30) - point = models.PointField(geography=True) + objects = models.GeoManager() + class Meta: + abstract = True + app_label = 'geogapp' + def __str__(self): return self.name -@python_2_unicode_compatible -class Zipcode(models.Model): - code = models.CharField(max_length=10) +class City(NamedModel): + point = models.PointField(geography=True) + + +class Zipcode(NamedModel): poly = models.PolygonField(geography=True) - objects = models.GeoManager() - - def __str__(self): - return self.code -@python_2_unicode_compatible -class County(models.Model): - name = models.CharField(max_length=25) +class County(NamedModel): state = models.CharField(max_length=20) mpoly = models.MultiPolygonField(geography=True) - objects = models.GeoManager() def __str__(self): return ' County, '.join([self.name, self.state]) diff --git a/django/contrib/gis/tests/inspectapp/models.py b/django/contrib/gis/tests/inspectapp/models.py index 37c67a72fe..caf45fad9a 100644 --- a/django/contrib/gis/tests/inspectapp/models.py +++ b/django/contrib/gis/tests/inspectapp/models.py @@ -2,6 +2,7 @@ from django.contrib.gis.db import models class AllOGRFields(models.Model): + f_decimal = models.FloatField() f_float = models.FloatField() f_int = models.IntegerField() @@ -13,3 +14,6 @@ class AllOGRFields(models.Model): point = models.PointField() objects = models.GeoManager() + + class Meta: + app_label = 'inspectapp' diff --git a/django/contrib/gis/tests/layermap/models.py b/django/contrib/gis/tests/layermap/models.py index 1b66c6d94c..246af1458d 100644 --- a/django/contrib/gis/tests/layermap/models.py +++ b/django/contrib/gis/tests/layermap/models.py @@ -1,61 +1,75 @@ from django.contrib.gis.db import models +from django.utils.encoding import python_2_unicode_compatible -class State(models.Model): - name = models.CharField(max_length=20) +@python_2_unicode_compatible +class NamedModel(models.Model): + name = models.CharField(max_length=25) + objects = models.GeoManager() + class Meta: + abstract = True + app_label = 'layermap' -class County(models.Model): - name = models.CharField(max_length=25) + def __str__(self): + return self.name + + +class State(NamedModel): + pass + + +class County(NamedModel): state = models.ForeignKey(State) mpoly = models.MultiPolygonField(srid=4269) # Multipolygon in NAD83 - objects = models.GeoManager() -class CountyFeat(models.Model): - name = models.CharField(max_length=25) +class CountyFeat(NamedModel): poly = models.PolygonField(srid=4269) - objects = models.GeoManager() -class City(models.Model): - name = models.CharField(max_length=25) +class City(NamedModel): name_txt = models.TextField(default='') population = models.IntegerField() density = models.DecimalField(max_digits=7, decimal_places=1) dt = models.DateField() point = models.PointField() - objects = models.GeoManager() -class Interstate(models.Model): - name = models.CharField(max_length=20) +class Interstate(NamedModel): length = models.DecimalField(max_digits=6, decimal_places=2) path = models.LineStringField() - objects = models.GeoManager() # Same as `City` above, but for testing model inheritance. -class CityBase(models.Model): - name = models.CharField(max_length=25) +class CityBase(NamedModel): population = models.IntegerField() density = models.DecimalField(max_digits=7, decimal_places=1) point = models.PointField() - objects = models.GeoManager() class ICity1(CityBase): dt = models.DateField() + class Meta(CityBase.Meta): + pass + class ICity2(ICity1): dt_time = models.DateTimeField(auto_now=True) + class Meta(ICity1.Meta): + pass + class Invalid(models.Model): point = models.PointField() + class Meta: + app_label = 'layermap' + + # Mapping dictionaries for the models above. co_mapping = {'name': 'Name', 'state': {'name': 'State'}, # ForeignKey's use another mapping dictionary for the _related_ Model (State in this case). diff --git a/django/contrib/gis/tests/relatedapp/models.py b/django/contrib/gis/tests/relatedapp/models.py index 6d4b530c58..3b4364f7b9 100644 --- a/django/contrib/gis/tests/relatedapp/models.py +++ b/django/contrib/gis/tests/relatedapp/models.py @@ -2,21 +2,28 @@ from django.contrib.gis.db import models from django.utils.encoding import python_2_unicode_compatible -@python_2_unicode_compatible -class Location(models.Model): - point = models.PointField() +class SimpleModel(models.Model): + objects = models.GeoManager() + class Meta: + abstract = True + app_label = 'relatedapp' + + +@python_2_unicode_compatible +class Location(SimpleModel): + point = models.PointField() + def __str__(self): return self.point.wkt @python_2_unicode_compatible -class City(models.Model): +class City(SimpleModel): name = models.CharField(max_length=50) state = models.CharField(max_length=2) location = models.ForeignKey(Location) - objects = models.GeoManager() def __str__(self): return self.name @@ -24,17 +31,20 @@ class City(models.Model): class AugmentedLocation(Location): extra_text = models.TextField(blank=True) + objects = models.GeoManager() + class Meta: + app_label = 'relatedapp' -class DirectoryEntry(models.Model): + +class DirectoryEntry(SimpleModel): listing_text = models.CharField(max_length=50) location = models.ForeignKey(AugmentedLocation) - objects = models.GeoManager() @python_2_unicode_compatible -class Parcel(models.Model): +class Parcel(SimpleModel): name = models.CharField(max_length=30) city = models.ForeignKey(City) center1 = models.PointField() @@ -42,26 +52,22 @@ class Parcel(models.Model): center2 = models.PointField(srid=2276, db_column='mycenter') border1 = models.PolygonField() border2 = models.PolygonField(srid=2276) - objects = models.GeoManager() def __str__(self): return self.name # These use the GeoManager but do not have any geographic fields. -class Author(models.Model): +class Author(SimpleModel): name = models.CharField(max_length=100) dob = models.DateField() - objects = models.GeoManager() -class Article(models.Model): +class Article(SimpleModel): title = models.CharField(max_length=100) author = models.ForeignKey(Author, unique=True) - objects = models.GeoManager() -class Book(models.Model): +class Book(SimpleModel): title = models.CharField(max_length=100) author = models.ForeignKey(Author, related_name='books', null=True) - objects = models.GeoManager()