vendredi 14 novembre 2014

Django, affichage et modification des relations de clé étrangère inverses dans admin - Stack Overflow


I am making a web game in which each world can be part of one alliance.


class World(models.Model):
# rest of Model
alliance = models.ForeignKey('Alliance', related_name='allmember', default=None, blank=True, null=True)
officer = models.NullBooleanField()
leader = models.NullBooleanField()

class Alliance(models.Model):
allianceid = models.AutoField(primary_key=True)
alliance_name = models.CharField(max_length=20, unique=True)
alliance_desc = models.TextField(max_length=200)

I gather that using inlines, I can display the members of an alliance on the alliance page. However, I can only edit the officer and leader statuses, whereas I want to be able to edit the membership status as well. Here is the inline I am using.


class MemberInline(admin.TabularInline):
model = World
fk_name = 'alliance'
# excludes

class AllianceAdmin(admin.ModelAdmin):
inlines = [
MemberInline,
]

I suppose what I really want to ask is if I can edit a foreign key relationship in the admin site from the target model rather than the originator.



I am making a web game in which each world can be part of one alliance.


class World(models.Model):
# rest of Model
alliance = models.ForeignKey('Alliance', related_name='allmember', default=None, blank=True, null=True)
officer = models.NullBooleanField()
leader = models.NullBooleanField()

class Alliance(models.Model):
allianceid = models.AutoField(primary_key=True)
alliance_name = models.CharField(max_length=20, unique=True)
alliance_desc = models.TextField(max_length=200)

I gather that using inlines, I can display the members of an alliance on the alliance page. However, I can only edit the officer and leader statuses, whereas I want to be able to edit the membership status as well. Here is the inline I am using.


class MemberInline(admin.TabularInline):
model = World
fk_name = 'alliance'
# excludes

class AllianceAdmin(admin.ModelAdmin):
inlines = [
MemberInline,
]

I suppose what I really want to ask is if I can edit a foreign key relationship in the admin site from the target model rather than the originator.


0 commentaires:

Enregistrer un commentaire