I have a Product model, an Image Model and a Category Model.

A Product can have multiple Images(Foreign Key) and a Product can be in 
multiple Categories a Category can contain multiple Products.

A Category can have multiple subcategories(key to itself).


class Category(MetaData): 
 parent = models.ForeignKey('self', blank=True, null=True, verbose_name='parent 
category', on_delete=models.CASCADE) 

class ProductMetaData): 
  categories = models.ManyToManyField(Category) 

class ProductImage(models.Model):  
  product = models.ForeignKey(Product, related_name='image', on_delete=
models.CASCADE)



In Product Django Admin: 

class ProductDocumentInline(admin.TabularInline): 
 model = ProductDocument class ProductAdmin(MetaData):
 inlines = [ProductImageInline]
 fieldsets = (
 ('Product Data', {
 'fields': ('name', 'short_description', 'description')
 }),
 ('SEO', {
 'classes': ('collapse',),
 'fields': ('meta_title', 'meta_description', 'slug', 'canonical')
 }),
 ('MetaData', {
 'classes': ('collapse',),
 'fields': (('created_at', 'created_by'), ('updated_at', 'updated_by'))
 }),
 )
 readonly_fields = ('created_at', 'updated_at', 'created_by', 'updated_by')
 list_display = ('name', 'updated_at')
 ordering = ('-updated_at',)
 search_fields = ('name',)


admin.site.register(Product, ProductAdmin)
admin.site.register(ProductImage)



Issues:

   1. 
   
   If I don't customize fieldsets (grouped, ordered) the Categories appear 
   like default in the middle of the form. If there are customized as in my 
   example they don't appear.
   2. 
   
   If they don't appear Products without Categories can be created and I 
   don't want that. I want a product to have at least one category.
   3. 
   
   Now the inline Images appear below all Product fields. 
   
I want the Categories to appear first, then normal fields for 
Product(grouped,ordered), Images inline and at the end the SEO and metadata 
fields. How can this be done ?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/37bf83ae-cdca-4c73-8ace-747386513e53%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to