Okay, newbie here. So I am working on a project where the requirement is : I have to make a Customer model ,where admin/staff can add the customer's details. Now the problem is admin/staff can add multiple address against a customer.I can't find any proper idea ,how would I make it. But still I made a plan ..
and I added some code.
customer-models.py
from __future__ import unicode_literals
from django.contrib.postgres.fields import JSONField
from decimal import Decimal
from django.db import models
from django.utils.safestring import mark_safe
# Create your models here.
class customer(models.Model):
first_name = models.CharField(max_length=150)
last_name = models.CharField(max_length=150)
profile_image = models.FileField()
phone_number = models.BigIntegerField()
def profile(self):
if self.profile_image!="":
return mark_safe('<img src="/media/%s" width="150" height="150" />' % (self.profile_image))
else:
return "";
profile.short_description = 'Image'
# profile.allow_tags = True
Customer_address-models.py
from __future__ import unicode_literals
from customer.models import customer
from django.db import models
# Create your models here.
class Address(models.Model):
customer = models.ForeignKey(customer,default=0)
country = models.CharField(max_length=150)
state = models.CharField(max_length=150)
city =models.CharField(max_length=150)
pin_code = models.BigIntegerField()
# def customer_address(self):
# return fields = ["country","state","city","pin_code"]
customer - admin.py
from __future__ import unicode_literals
from .models import customer
from customer_address.models import Address
from django.contrib import admin
# Register your models here.
class CustomerAddressInline(admin.StackedInline):
model = Address
class CustomerAdmin(admin.ModelAdmin):
list_display = ["first_name","last_name","phone_number","profile"]
list_select_related = True
inlines = [
CustomerAddressInline,
]
search_fields = ["first_name","last_name","phone_number"]
fields = ( "first_name","last_name","phone_number",'profile',"profile_image","customer_address" )
readonly_fields = ('profile',)
class Meta:
model = customer
admin.site.register(customer,CustomerAdmin)
cant figure it out,how I show/edit/instert all fields as address in customer module from admin.A little help would be much appreciated Thank you P.S : I am using django-1.11.10