-
Notifications
You must be signed in to change notification settings - Fork 3
Place Model #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
pizzapanther
wants to merge
5
commits into
armstrong:master
Choose a base branch
from
pizzapanther:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Place Model #1
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| *.pyc | ||
| build | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| from django.contrib import admin | ||
| from django.utils.translation import ugettext as _ | ||
|
|
||
| from armstrong.core.arm_content.admin import fieldsets | ||
| from armstrong import hatband | ||
|
|
||
| from .models import Place | ||
|
|
||
| class PlaceAdmin (admin.ModelAdmin): | ||
| fieldsets = ( | ||
| (None, { | ||
| 'fields': ('title', 'slug', 'summary'), | ||
| }), | ||
|
|
||
| (_('Location'), { | ||
| 'fields': ('address1', 'address2', ('city', 'state'), ('zipcode', 'country'), 'coordinate'), | ||
| }), | ||
|
|
||
| fieldsets.TAXONOMY, | ||
| fieldsets.PUBLICATION, | ||
| fieldsets.AUTHORS, | ||
| ) | ||
|
|
||
| hatband.site.register(Place, PlaceAdmin) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,129 @@ | ||
| # -*- coding: utf-8 -*- | ||
| import datetime | ||
| from south.db import db | ||
| from south.v2 import SchemaMigration | ||
| from django.db import models | ||
|
|
||
|
|
||
| class Migration(SchemaMigration): | ||
|
|
||
| def forwards(self, orm): | ||
| # Adding model 'Place' | ||
| db.create_table('places_place', ( | ||
| ('content_ptr', self.gf('django.db.models.fields.related.OneToOneField')(to=orm['content.Content'], unique=True, primary_key=True)), | ||
| ('address1', self.gf('django.db.models.fields.CharField')(max_length=100, null=True, blank=True)), | ||
| ('address2', self.gf('django.db.models.fields.CharField')(max_length=100, null=True, blank=True)), | ||
| ('zipcode', self.gf('django.db.models.fields.CharField')(max_length=30, null=True, blank=True)), | ||
| ('city', self.gf('django.db.models.fields.CharField')(max_length=100, null=True, blank=True)), | ||
| ('state', self.gf('django.db.models.fields.CharField')(max_length=100, null=True, blank=True)), | ||
| ('country', self.gf('django.db.models.fields.CharField')(max_length=100, null=True, blank=True)), | ||
| ('coordinate', self.gf('django.contrib.gis.db.models.fields.PointField')()), | ||
| )) | ||
| db.send_create_signal('places', ['Place']) | ||
|
|
||
| def backwards(self, orm): | ||
| # Deleting model 'Place' | ||
| db.delete_table('places_place') | ||
|
|
||
| models = { | ||
| 'arm_access.accessobject': { | ||
| 'Meta': {'object_name': 'AccessObject'}, | ||
| 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}) | ||
| }, | ||
| 'arm_sections.section': { | ||
| 'Meta': {'object_name': 'Section'}, | ||
| 'full_slug': ('django.db.models.fields.CharField', [], {'max_length': '255', 'blank': 'True'}), | ||
| 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), | ||
| 'level': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}), | ||
| 'lft': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}), | ||
| 'parent': ('mptt.fields.TreeForeignKey', [], {'to': "orm['arm_sections.Section']", 'null': 'True', 'blank': 'True'}), | ||
| 'rght': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}), | ||
| 'slug': ('django.db.models.fields.SlugField', [], {'max_length': '50'}), | ||
| 'summary': ('django.db.models.fields.TextField', [], {'default': "''", 'blank': 'True'}), | ||
| 'title': ('django.db.models.fields.CharField', [], {'max_length': '255'}), | ||
| 'tree_id': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}) | ||
| }, | ||
| 'auth.group': { | ||
| 'Meta': {'object_name': 'Group'}, | ||
| 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), | ||
| 'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '80'}), | ||
| 'permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}) | ||
| }, | ||
| 'auth.permission': { | ||
| 'Meta': {'ordering': "('content_type__app_label', 'content_type__model', 'codename')", 'unique_together': "(('content_type', 'codename'),)", 'object_name': 'Permission'}, | ||
| 'codename': ('django.db.models.fields.CharField', [], {'max_length': '100'}), | ||
| 'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['contenttypes.ContentType']"}), | ||
| 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), | ||
| 'name': ('django.db.models.fields.CharField', [], {'max_length': '50'}) | ||
| }, | ||
| 'auth.user': { | ||
| 'Meta': {'object_name': 'User'}, | ||
| 'date_joined': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}), | ||
| 'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'blank': 'True'}), | ||
| 'first_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}), | ||
| 'groups': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Group']", 'symmetrical': 'False', 'blank': 'True'}), | ||
| 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), | ||
| 'is_active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}), | ||
| 'is_staff': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), | ||
| 'is_superuser': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), | ||
| 'last_login': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}), | ||
| 'last_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}), | ||
| 'password': ('django.db.models.fields.CharField', [], {'max_length': '128'}), | ||
| 'user_permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}), | ||
| 'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '30'}) | ||
| }, | ||
| 'content.content': { | ||
| 'Meta': {'object_name': 'Content'}, | ||
| 'access': ('armstrong.core.arm_access.fields.AccessField', [], {}), | ||
| 'authors': ('armstrong.core.arm_content.fields.authors.AuthorsField', [], {'to': "orm['auth.User']", 'override_field_name': "'authors_override'", 'symmetrical': 'False', 'extra_field_name': "'authors_extra'", 'blank': 'True'}), | ||
| 'authors_extra': ('django.db.models.fields.CharField', [], {'max_length': '200', 'blank': 'True'}), | ||
| 'authors_override': ('django.db.models.fields.CharField', [], {'max_length': '200', 'blank': 'True'}), | ||
| 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), | ||
| 'pub_date': ('django.db.models.fields.DateTimeField', [], {'db_index': 'True'}), | ||
| 'pub_status': ('django.db.models.fields.CharField', [], {'max_length': '1'}), | ||
| 'sections': ('django.db.models.fields.related.ManyToManyField', [], {'blank': 'True', 'related_name': "'content_content_alternates'", 'null': 'True', 'symmetrical': 'False', 'to': "orm['arm_sections.Section']"}), | ||
| 'sites': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['sites.Site']", 'symmetrical': 'False'}), | ||
| 'slug': ('django.db.models.fields.SlugField', [], {'max_length': '50'}), | ||
| 'summary': ('django.db.models.fields.TextField', [], {}), | ||
| 'title': ('django.db.models.fields.CharField', [], {'max_length': '255'}) | ||
| }, | ||
| 'contenttypes.contenttype': { | ||
| 'Meta': {'ordering': "('name',)", 'unique_together': "(('app_label', 'model'),)", 'object_name': 'ContentType', 'db_table': "'django_content_type'"}, | ||
| 'app_label': ('django.db.models.fields.CharField', [], {'max_length': '100'}), | ||
| 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), | ||
| 'model': ('django.db.models.fields.CharField', [], {'max_length': '100'}), | ||
| 'name': ('django.db.models.fields.CharField', [], {'max_length': '100'}) | ||
| }, | ||
| 'places.place': { | ||
| 'Meta': {'object_name': 'Place', '_ormbases': ['content.Content']}, | ||
| 'address1': ('django.db.models.fields.CharField', [], {'max_length': '100', 'null': 'True', 'blank': 'True'}), | ||
| 'address2': ('django.db.models.fields.CharField', [], {'max_length': '100', 'null': 'True', 'blank': 'True'}), | ||
| 'city': ('django.db.models.fields.CharField', [], {'max_length': '100', 'null': 'True', 'blank': 'True'}), | ||
| 'content_ptr': ('django.db.models.fields.related.OneToOneField', [], {'to': "orm['content.Content']", 'unique': 'True', 'primary_key': 'True'}), | ||
| 'coordinate': ('django.contrib.gis.db.models.fields.PointField', [], {}), | ||
| 'country': ('django.db.models.fields.CharField', [], {'max_length': '100', 'null': 'True', 'blank': 'True'}), | ||
| 'state': ('django.db.models.fields.CharField', [], {'max_length': '100', 'null': 'True', 'blank': 'True'}), | ||
| 'zipcode': ('django.db.models.fields.CharField', [], {'max_length': '30', 'null': 'True', 'blank': 'True'}) | ||
| }, | ||
| 'sites.site': { | ||
| 'Meta': {'ordering': "('domain',)", 'object_name': 'Site', 'db_table': "'django_site'"}, | ||
| 'domain': ('django.db.models.fields.CharField', [], {'max_length': '100'}), | ||
| 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), | ||
| 'name': ('django.db.models.fields.CharField', [], {'max_length': '50'}) | ||
| }, | ||
| 'taggit.tag': { | ||
| 'Meta': {'object_name': 'Tag'}, | ||
| 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), | ||
| 'name': ('django.db.models.fields.CharField', [], {'max_length': '100'}), | ||
| 'slug': ('django.db.models.fields.SlugField', [], {'unique': 'True', 'max_length': '100'}) | ||
| }, | ||
| 'taggit.taggeditem': { | ||
| 'Meta': {'object_name': 'TaggedItem'}, | ||
| 'content_type': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'taggit_taggeditem_tagged_items'", 'to': "orm['contenttypes.ContentType']"}), | ||
| 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), | ||
| 'object_id': ('django.db.models.fields.IntegerField', [], {'db_index': 'True'}), | ||
| 'tag': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'taggit_taggeditem_items'", 'to': "orm['taggit.Tag']"}) | ||
| } | ||
| } | ||
|
|
||
| complete_apps = ['places'] |
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| from django.contrib.gis.db import models | ||
| from django.utils.translation import ugettext as _ | ||
|
|
||
| from armstrong.apps.content.models import Content | ||
|
|
||
| class Place (Content): | ||
| address1 = models.CharField(_('Address 1'), max_length=100, blank=True, null=True) | ||
| address2 = models.CharField(_('Address 2'), max_length=100, blank=True, null=True) | ||
| zipcode = models.CharField(_('Zip code'), max_length=30, blank=True, null=True) | ||
| city = models.CharField(max_length=100, blank=True, null=True) | ||
| state = models.CharField(_('State/Province'), max_length=100, blank=True, null=True) | ||
| country = models.CharField(max_length=100, blank=True, null=True) | ||
|
|
||
| coordinate = models.PointField() | ||
|
|
||
| objects = models.GeoManager() | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| import datetime | ||
|
|
||
| from django.test import TestCase | ||
| from django.core.urlresolvers import reverse, resolve | ||
|
|
||
| from django.contrib.gis.geos import Point | ||
| from django.contrib.gis.measure import D | ||
|
|
||
| from .models import Place | ||
|
|
||
| class PlacesTestCase (TestCase): | ||
| def setUp(self): | ||
| self.home = Place( | ||
| address1 = '1206 Halls Bridge', | ||
| address2 = None, | ||
| zipcode = '77573', | ||
| city = 'League City', | ||
| state = 'TX', | ||
| country = 'US', | ||
| coordinate = Point(-95.087372, 29.516589), | ||
|
|
||
| pub_date = datetime.datetime.now() | ||
| ) | ||
| self.home.save() | ||
|
|
||
| self.work = Place( | ||
| address1 = '3657 Briarpark Drive', | ||
| address2 = 'Suite 101', | ||
| zipcode = '77042', | ||
| city = 'Houston', | ||
| state = 'TX', | ||
| country = 'US', | ||
| coordinate = Point(-95.54835, 29.72546), | ||
|
|
||
| pub_date = datetime.datetime.now() | ||
| ) | ||
| self.work.save() | ||
|
|
||
| def tearDown(self): | ||
| self.home.delete() | ||
| self.work.delete() | ||
|
|
||
| def test_model (self): | ||
| bay_brook_mall = Point(-95.14820, 29.54211) | ||
| qs = Place.objects.filter(coordinate__distance_lte=(bay_brook_mall, D(mi=5))) | ||
| self.assertEqual(qs.count(), 1) | ||
| self.assertEqual(qs[0].id, self.home.id) | ||
|
|
||
| qs = Place.objects.filter(coordinate__distance_lte=(bay_brook_mall, D(mi=30))) | ||
| self.assertEqual(qs.count(), 2) | ||
|
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should this be nullable too? It seems like the coordinate is the most important aspect, but from a practical workflow perspective, sometimes you may only have an address and you'd like to do the geolocation out-of-band, and making
coordinaterequired limits how you can do that.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The one essential piece of info a place should have is that it is located somewhere. That is what my thought was. Also previously I've had problems with geospatial queries in Postgres when the fields are null. This may not be the case anymore, but I've always avoided nullable point fields since then especially since it is the most important field in the model.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think having a required
PointFieldon aPlaceis a fair requirement.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
on a philosophical django tangent... we've had the idea of enforcing different levels of data validation. Like an unpublished article doesn't need a slug, but a published one does, so should the slugfield be required? As I typed that out... I think the answer is yes. before the save() hits, you should just pre-generate one, even if it's gibberish. Likewise here, we can assume the implementer has figured out how to get the latlong already, or decides to use a dummy latlong and then fills in the real one later (like how Google maps used to default to the geographic center of the continental US).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When I implemented the model on the front end I have a button that the user clicks to look up an address on google maps and fills in the coordinates. Originally, I wanted to include this functionality with the Armstrong contribution by using http://mapstraction.com/. Mapstraction would allow you to switch between map providers. However, I never got it to work right and had to finish with a quick implementation of just google maps in the client's code. Now that I have sometime, I could probably revisit it if you think it is appropriate to include with the contribution.