Merge branch 'development' into diego
This commit is contained in:
@@ -1,13 +1,35 @@
|
|||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
|
|
||||||
|
from .forms import CustomUserChangeForm, CustomUserCreationForm
|
||||||
|
|
||||||
from . import models
|
from . import models
|
||||||
|
from .forms import CustomUserChangeForm, CustomUserCreationForm
|
||||||
# Register your models here.
|
# Register your models here.
|
||||||
|
|
||||||
|
from django.contrib.auth import get_user_model
|
||||||
|
|
||||||
|
User = get_user_model()
|
||||||
|
|
||||||
|
|
||||||
class UserAdmin(admin.ModelAdmin):
|
class UserAdmin(admin.ModelAdmin):
|
||||||
|
add_form = CustomUserCreationForm
|
||||||
|
form = CustomUserChangeForm
|
||||||
|
model = User
|
||||||
|
|
||||||
list_display = ('email', 'full_name', 'role', 'company', 'email_verified', 'is_active', 'is_staff', 'created', 'last_visit')
|
list_display = ('email', 'full_name', 'role', 'company', 'email_verified', 'is_active', 'is_staff', 'created', 'last_visit')
|
||||||
list_filter = ('is_active', 'is_staff', 'email_verified')
|
list_filter = ('is_active', 'is_staff', 'email_verified')
|
||||||
search_fields = ('email', 'full_name', 'company')
|
search_fields = ('email', 'full_name', 'company__short_name')
|
||||||
|
|
||||||
|
fieldsets = (
|
||||||
|
(None, {'fields': ('email', 'password','full_name', 'role', 'notify','provider','email_verified','company','is_active')}),
|
||||||
|
('Permissions', {'fields': ('is_staff', 'groups')}),
|
||||||
|
)
|
||||||
|
|
||||||
|
add_fieldsets = (
|
||||||
|
(None, {
|
||||||
|
'classes': ('wide',),
|
||||||
|
'fields': ('email', 'password1', 'password2', 'is_staff', 'is_active')}
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
admin.site.register(models.CustomUser, UserAdmin)
|
admin.site.register(models.CustomUser, UserAdmin)
|
||||||
|
|||||||
27
core/forms.py
Normal file
27
core/forms.py
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
from django import forms
|
||||||
|
from django.contrib.auth.forms import UserChangeForm, UserCreationForm
|
||||||
|
from django.forms import ModelForm
|
||||||
|
from django.contrib.auth import get_user_model
|
||||||
|
|
||||||
|
User = get_user_model()
|
||||||
|
|
||||||
|
|
||||||
|
class CustomUserCreationForm(UserCreationForm):
|
||||||
|
|
||||||
|
class Meta(UserCreationForm.Meta):
|
||||||
|
|
||||||
|
model = User
|
||||||
|
|
||||||
|
UserCreationForm.Meta.fields = ('email',)
|
||||||
|
fields = UserCreationForm.Meta.fields + ('full_name','role', 'notify', 'provider', 'email_verified', 'company', 'is_active', 'is_staff')
|
||||||
|
UserCreationForm.Meta.fields = ('password1','password2',)
|
||||||
|
|
||||||
|
|
||||||
|
class CustomUserChangeForm(UserChangeForm):
|
||||||
|
|
||||||
|
class Meta(UserChangeForm.Meta):
|
||||||
|
model = User
|
||||||
|
UserChangeForm.Meta.fields = ('email',)
|
||||||
|
fields = UserChangeForm.Meta.fields + ('full_name','role', 'notify', 'provider', 'email_verified', 'company', 'is_active', 'is_staff')
|
||||||
|
UserChangeForm.Meta.fields = ('password1','password2',)
|
||||||
|
|
||||||
@@ -35,11 +35,11 @@ class Command(BaseCommand):
|
|||||||
|
|
||||||
def handle(self, *args, **kwargs):
|
def handle(self, *args, **kwargs):
|
||||||
print("Create fake data to populate database\n")
|
print("Create fake data to populate database\n")
|
||||||
|
'''
|
||||||
print("Deleting existing Product and Company instances")
|
print("Deleting existing Product and Company instances")
|
||||||
Product.objects.all().delete()
|
Product.objects.all().delete()
|
||||||
Company.objects.all().delete()
|
Company.objects.all().delete()
|
||||||
|
'''
|
||||||
# start faker
|
# start faker
|
||||||
fake = Faker()
|
fake = Faker()
|
||||||
Faker.seed(0)
|
Faker.seed(0)
|
||||||
|
|||||||
@@ -34,6 +34,12 @@ class AttributeTag(TagTreeModel):
|
|||||||
# autocomplete_view = 'myapp.views.hobbies_autocomplete'
|
# autocomplete_view = 'myapp.views.hobbies_autocomplete'
|
||||||
|
|
||||||
|
|
||||||
|
def product_image_path(instance, filename):
|
||||||
|
"""Add the instance's id to the path
|
||||||
|
"""
|
||||||
|
return f"products/{instance.id}/{filename}"
|
||||||
|
|
||||||
|
|
||||||
class Product(models.Model):
|
class Product(models.Model):
|
||||||
|
|
||||||
SYNCHRONIZED = 'SYNCHRONIZED'
|
SYNCHRONIZED = 'SYNCHRONIZED'
|
||||||
@@ -50,7 +56,7 @@ class Product(models.Model):
|
|||||||
sku = models.CharField('Referencia de producto', max_length=255, null=True, blank=True )
|
sku = models.CharField('Referencia de producto', max_length=255, null=True, blank=True )
|
||||||
name = models.CharField('Nombre del producto', max_length=500, null=True, blank=True)
|
name = models.CharField('Nombre del producto', max_length=500, null=True, blank=True)
|
||||||
description = models.TextField('Descripción', null=True, blank=True)
|
description = models.TextField('Descripción', null=True, blank=True)
|
||||||
image = models.ImageField('Imagen del producto', upload_to='products/', null=True, blank=True)
|
image = models.ImageField('Imagen del producto', upload_to=product_image_path, null=True, blank=True)
|
||||||
url = models.URLField('URL del producto', null=True, blank=True, max_length=1000)
|
url = models.URLField('URL del producto', null=True, blank=True, max_length=1000)
|
||||||
price = models.DecimalField('Precio', max_digits=10, decimal_places=2, null=True, blank=True)
|
price = models.DecimalField('Precio', max_digits=10, decimal_places=2, null=True, blank=True)
|
||||||
shipping_cost = models.DecimalField('Gastos de envío', max_digits=10, decimal_places=2, null=True, blank=True)
|
shipping_cost = models.DecimalField('Gastos de envío', max_digits=10, decimal_places=2, null=True, blank=True)
|
||||||
|
|||||||
Reference in New Issue
Block a user