Django admin to edit inline foreign keys

Is there a way to make the "GeoData" display embedded in the admin for the "Shop" and "Park" objects?

(One store / park may contain several locations)

# Location data class GeoData(models.Model): lat = models.FloatField() lon = models.FloatField() description = models.TextField() # Parent class for every object with location data class GeoEntity(models.Model): title = models.CharField(max_length=32) position = models.ForeignKey(GeoData) class Shop(GeoEntity): tel = models.CharField(max_length=32) address = models.TextField() class Park(GeoEntity): wifi = models.BooleanField() area = models.IntegerField() 

I tried many options from Google, but none of them worked.

Thanks.

+4
source share
2 answers

Try adding to your admin.py for these classes. Try something like this.

  class ShopAdmin(admin.ModelAdmin): list_display = ('tel', 'address', 'position') 

This can be found in the Djangobook admin chapter.
http://www.djangobook.com/en/2.0/chapter06.html

+1
source

Try filter_horizontal: http://www.djangobook.com/en/2.0/chapter06.html ?

It only works with ManyToManyFields, so you need to change your models.

0
source

Source: https://habr.com/ru/post/1435368/


All Articles