Commit 40b449e8 authored by Ben Waters's avatar Ben Waters
Browse files

Update on models

parent d249e696
......@@ -5,8 +5,8 @@
<libraries />
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="PublishConfigData" serverName="myserver" />
<component name="ProjectDictionaryState">
<dictionary name="bwaters" />
\ No newline at end of file
......@@ -11,11 +11,18 @@
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="jdk" jdkName="Python 2.7.6 virtualenv at ~/Environments/ff" jdkType="Python SDK" />
<orderEntry type="sourceFolder" forTests="false" />
<component name="ReSTService">
<option name="workdir" value="docs" />
<option name="DOC_DIR" value="docs" />
<component name="TemplatesService">
<option name="TEMPLATE_CONFIGURATION" value="Django" />
<component name="TestRunnerService">
<option name="PROJECT_TEST_RUNNER" value="Unittests" />
<component name="InspectionProjectProfileManager">
<profile version="1.0" is_locked="false">
<option name="myName" value="Project Default" />
<option name="myLocal" value="false" />
<inspection_tool class="PyPackageRequirementsInspection" enabled="true" level="WARNING" enabled_by_default="true">
<option name="ignoredPackages">
<list size="1">
<item index="0" class="java.lang.String" itemvalue="djangorestframework" />
\ No newline at end of file
<component name="InspectionProjectProfileManager">
<option name="PROJECT_PROFILE" value="Project Default" />
<option name="USE_PROJECT_PROFILE" value="true" />
<version value="1.0" />
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VagrantProjectSettings">
<option name="instanceFolder" value="" />
<option name="provider" value="" />
This diff is collapsed.
......@@ -6,8 +6,23 @@ from django.db.models.signals import post_save
from django.dispatch import receiver
from rest_framework.authtoken.models import Token
from rest_framework import serializers
from model_utils.models import TimeStampedModel
from django.contrib.auth.models import User
class University(TimeStampedModel):
name = models.CharField(max_length=255)
city = models.CharField(max_length=255)
state = models.CharField(max_length=2)
def __unicode__(self):
class UniversitySerializer(serializers.ModelSerializer):
class Meta:
model = University
fields = ('id', 'name', 'city', 'state')
@receiver(post_save, sender=get_user_model())
def create_auth_token(sender, instance=None, created=False, **kwargs):
if created:
......@@ -16,4 +31,4 @@ def create_auth_token(sender, instance=None, created=False, **kwargs):
class UserSerializer(serializers.ModelSerializer):
class Meta:
model = User
fields = ('id', 'username', 'email')
fields = ('id', 'username', 'first_name', 'last_name', 'email')
from django.shortcuts import render
from rest_framework import viewsets
from rest_framework.response import Response
from rest_framework import status
from rest_framework.decorators import detail_route
from django.contrib.auth.models import User
from .models import University, UniversitySerializer, UserSerializer
# Create your views here.
class UniversityViewSet(viewsets.ModelViewSet):
queryset = University.objects.all()
serializer_class = UniversitySerializer
class UserViewSet(viewsets.ModelViewSet):
queryset = User.objects.all()
serializer_class = UserSerializer
def set_password(self, request, pk=None):
user = self.get_object()
serializer = UserSerializer(data=request.DATA)
if serializer.is_valid():
return Response({'status': 'password set'})
return Response(serializer.errors,
\ No newline at end of file
No preview for this file type
......@@ -35,7 +35,6 @@ SITE_ID= 1
DATABASE_ROUTERS = ['geo.router.GeoRouter']
# Application definition
......@@ -47,7 +46,6 @@ INSTALLED_APPS = (
......@@ -78,17 +76,10 @@ DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'ff',
'USER': 'ffuser',
'PASSWORD': '14ff!',
'USER': 'ffUser',
'PASSWORD': '14ffUser!',
'HOST': 'localhost',
'location': {
'ENGINE': 'django.contrib.gis.db.backends.postgis',
'NAME': 'geo',
'USER': 'geoUser',
'PASSWORD': '14geoUser!',
'HOST': 'localhost',
# Internationalization
No preview for this file type
......@@ -5,11 +5,16 @@ from rest_framework import routers
from django.contrib import admin
from geo.views import LocationViewSet
from geo.views import LocationViewSet, UserLocationViewSet
from core.views import UniversityViewSet, UserViewSet
router = routers.DefaultRouter()
router.register(r'locations', LocationViewSet)
router.register(r'universities', UniversityViewSet)
router.register(r'user-locations', UserLocationViewSet)
router.register(r'users', UserViewSet)
urlpatterns = patterns('',
# Examples:
from django.contrib.gis import admin
from django.contrib import admin
from .models import Location
# Register your models here.
class LocationAdmin(admin.GeoModelAdmin):
class LocationAdmin(admin.ModelAdmin):
pass, LocationAdmin)
# -*- coding: utf-8 -*-
from south.utils import datetime_utils as 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 'Location'
db.create_table(u'geo_location', (
db.send_create_signal(u'geo', ['Location'])
def backwards(self, orm):
# Deleting model 'Location'
models = {
u'geo.location': {
'Meta': {'object_name': 'Location'},
'area': ('django.db.models.fields.IntegerField', [], {}),
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'maxLon': ('django.db.models.fields.FloatField', [], {}),
'minLat': ('django.db.models.fields.FloatField', [], {}),
'minLon': ('django.db.models.fields.FloatField', [], {}),
'name': ('django.db.models.fields.CharField', [], {'max_length': '50'})
complete_apps = ['geo']
\ No newline at end of file
from django.contrib.gis.db import models
from django.db import models
from django.contrib.auth.models import User
from rest_framework import serializers
from model_utils.models import TimeStampedModel
# Create your models here.
class Location(models.Model):
name = models.CharField(max_length=50)
area = models.IntegerField()
uni = models.ForeignKey('core.University')
minLon = models.FloatField()
maxLon = models.FloatField()
minLat = models.FloatField()
minLat = models.FloatField()
objects = models.GeoManager()
maxLat = models.FloatField()
def __unicode__(self):
class LocationSerializer(serializers.ModelSerializer):
class Meta:
model = Location
fields = ('id', 'name', 'area', 'minLon', 'maxLon', 'minLat', 'maxLat')
uni = serializers.RelatedField(many=False)
class Meta:
model = Location
fields = ('id', 'name', 'uni', 'minLon', 'maxLon', 'minLat', 'maxLat')
class UserLocation(TimeStampedModel):
user = models.ForeignKey(User)
long = models.FloatField()
lat = models.FloatField()
def __unicode__(self):
return "%s %f %f", (self.user.username, self.long,
class UserLocationSerializer(serializers.ModelSerializer):
user = serializers.RelatedField(many=False)
class Meta:
model = UserLocation
fields = ('id', 'modified', 'user', 'lat', 'long')
\ No newline at end of file
......@@ -3,6 +3,7 @@ class GeoRouter(object):
A router to control all database operations on models in the
geo application.
def db_for_read(self, model, **hints):
Attempts to read geo models go to location.
......@@ -24,8 +25,8 @@ class GeoRouter(object):
Allow relations if a model in the geo app is involved.
if obj1._meta.app_label == 'geo' or \
obj2._meta.app_label == 'geo':
return True
obj2._meta.app_label == 'geo':
return True
return None
def allow_migrate(self, db, model):
from django.test import TestCase
# Create your tests here.
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment