Auto create UserProfile
This commit is contained in:
1 parent
863c36f98b
commit
7a15006455
3 files changed
+23
-6
No files matched your search
@@ -0,0 +1,7 @@
|
|||||||
|
from django.contrib import admin
|
||||||
|
from bbs.main.models import Product
|
||||||
|
|
||||||
|
class ProductAdmin(admin.ModelAdmin):
|
||||||
|
pass
|
||||||
|
|
||||||
|
admin.site.register(Product, ProductAdmin)
|
||||||
+14
-6
@@ -1,22 +1,24 @@
|
|||||||
from django.db import models
|
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
|
from django.db import models
|
||||||
|
from django.db.models.signals import post_save
|
||||||
|
from django.dispatch import receiver
|
||||||
|
|
||||||
class Product(models.Model):
|
class Product(models.Model):
|
||||||
|
|
||||||
def __unicode__(self):
|
def __unicode__(self):
|
||||||
return self.name
|
return self.name
|
||||||
|
|
||||||
description = models.CharField(max_length=256, blank=True)
|
|
||||||
name = models.CharField(max_length=64)
|
name = models.CharField(max_length=64)
|
||||||
sale_price_int = models.FloatField()
|
sale_price_int = models.FloatField()
|
||||||
sale_price_ext = models.FloatField()
|
sale_price_ext = models.FloatField()
|
||||||
|
description = models.CharField(max_length=256, blank=True)
|
||||||
volume_liter = models.FloatField(null=True)
|
volume_liter = models.FloatField(null=True)
|
||||||
alcohol_percent = models.FloatField(null=True)
|
alcohol_percent = models.FloatField(null=True)
|
||||||
image = models.ImageField(upload_to='uploads', blank=True)
|
image = models.ImageField(upload_to='uploads', blank=True)
|
||||||
created = models.DateTimeField(auto_now_add=True)
|
|
||||||
updated = models.DateTimeField(auto_now=True)
|
|
||||||
active = models.BooleanField(default=True)
|
active = models.BooleanField(default=True)
|
||||||
customer_support = models.CharField(max_length=32, blank=True)
|
customer_support = models.CharField(max_length=32, blank=True)
|
||||||
|
created = models.DateTimeField(auto_now_add=True)
|
||||||
|
updated = models.DateTimeField(auto_now=True)
|
||||||
|
|
||||||
class Order(models.Model):
|
class Order(models.Model):
|
||||||
user = models.ForeignKey(User)
|
user = models.ForeignKey(User)
|
||||||
@@ -34,10 +36,16 @@ class OrderLine(models.Model):
|
|||||||
|
|
||||||
class Transaction(models.Model):
|
class Transaction(models.Model):
|
||||||
user = models.ForeignKey(User)
|
user = models.ForeignKey(User)
|
||||||
created = models.DateTimeField(auto_now_add=True)
|
|
||||||
amount = models.FloatField()
|
amount = models.FloatField()
|
||||||
|
created = models.DateTimeField(auto_now_add=True)
|
||||||
|
|
||||||
class UserProfile(models.Model):
|
class UserProfile(models.Model):
|
||||||
user = models.ForeignKey(User, unique=True)
|
user = models.ForeignKey(User, unique=True)
|
||||||
balance = models.FloatField()
|
balance = models.FloatField(default=0.0)
|
||||||
image = models.ImageField(upload_to='uploads', blank=True)
|
image = models.ImageField(upload_to='uploads', blank=True)
|
||||||
|
|
||||||
|
# Create a new UserProfile object when we create a new User.
|
||||||
|
@receiver(post_save, sender=User)
|
||||||
|
def create_user_profile(sender, instance, created, **kwargs):
|
||||||
|
if created:
|
||||||
|
UserProfile.objects.create(user=instance)
|
||||||
@@ -150,3 +150,5 @@ LOGGING = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# User profile
|
||||||
|
AUTH_PROFILE_MODULE = 'main.UserProfile'
|
||||||
Reference in new issue
Block a user