Messing around with locations/coordinates
This commit is contained in:
parent
41d71d313f
commit
5838c62524
4 changed files with 30 additions and 16 deletions
|
@ -5,9 +5,9 @@ from django.urls import reverse
|
|||
from django.contrib.gis.geos import Point
|
||||
|
||||
from public.mixins import InConstructionMixin
|
||||
from localauth.helpers import name_to_coords
|
||||
|
||||
from .models import Inquiry
|
||||
from .helpers import name_to_coords
|
||||
|
||||
class InquiryCreateView(InConstructionMixin, CreateView):
|
||||
model = Inquiry
|
||||
|
|
|
@ -1,10 +1,13 @@
|
|||
from django.db import models
|
||||
from django.contrib.gis.db import models
|
||||
from django.contrib.gis.geos import Point
|
||||
from django.contrib.auth.models import AbstractBaseUser, BaseUserManager
|
||||
from django.contrib.auth import get_user_model
|
||||
from django.utils import timezone
|
||||
|
||||
from django_countries.fields import CountryField
|
||||
|
||||
from .helpers import profile_to_coords
|
||||
|
||||
class UserManager(BaseUserManager):
|
||||
use_in_migrations = True
|
||||
|
||||
|
@ -60,17 +63,34 @@ class User(AbstractBaseUser):
|
|||
has_module_perms = has_permission
|
||||
has_perm = has_permission
|
||||
|
||||
class Profile(models.Model):
|
||||
class AddressMixin(models.Model):
|
||||
street = models.CharField(max_length=64)
|
||||
city = models.CharField(max_length=64)
|
||||
zip = models.CharField(max_length=16)
|
||||
state = models.CharField(max_length=64, null=True, blank=True)
|
||||
country = CountryField()
|
||||
|
||||
class Meta:
|
||||
abstract = True
|
||||
|
||||
class LocationMixin(AddressMixin):
|
||||
coords = models.PointField()
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
if not self.coords:
|
||||
lat, lon = profile_to_coords(self)
|
||||
self.coords = Point(lon, lat)
|
||||
super().save(*args, **kwargs)
|
||||
|
||||
class Meta:
|
||||
abstract = True
|
||||
|
||||
class Profile(AddressMixin, models.Model):
|
||||
user = models.OneToOneField(User, models.CASCADE)
|
||||
company = models.CharField(max_length=64, null=True, blank=True)
|
||||
vat_id = models.CharField(max_length=32, null=True, blank=True)
|
||||
first_name = models.CharField(max_length=64)
|
||||
last_name = models.CharField(max_length=64)
|
||||
street = models.CharField(max_length=64)
|
||||
city = models.CharField(max_length=64)
|
||||
zip = models.CharField(max_length=16)
|
||||
state = models.CharField(max_length=64)
|
||||
country = CountryField()
|
||||
verified = models.BooleanField(default=False)
|
||||
enabled = models.BooleanField(default=True)
|
||||
|
||||
|
|
|
@ -1,23 +1,17 @@
|
|||
from django.contrib.gis.db import models
|
||||
|
||||
from localauth.models import User, Profile
|
||||
from localauth.models import User, Profile, LocationMixin
|
||||
|
||||
from django_countries.fields import CountryField
|
||||
|
||||
class PartnerProfile(Profile):
|
||||
pass
|
||||
|
||||
class Establishment(models.Model):
|
||||
class Establishment(LocationMixin, models.Model):
|
||||
owner = models.ForeignKey(PartnerProfile, models.CASCADE)
|
||||
name = models.CharField(max_length=64)
|
||||
stars = models.IntegerField(null=True, blank=True)
|
||||
superior = models.BooleanField(default=False)
|
||||
street = models.CharField(max_length=64)
|
||||
city = models.CharField(max_length=64)
|
||||
zip = models.CharField(max_length=16)
|
||||
state = models.CharField(max_length=64)
|
||||
country = CountryField()
|
||||
coords = models.PointField()
|
||||
verified = models.BooleanField(default=False)
|
||||
|
||||
class RoomCategory(models.Model):
|
||||
|
|
Loading…
Reference in a new issue