Note that there are some explanatory texts on larger screens.

plurals
  1. PODjango admin sharing inlines between apps
    primarykey
    data
    text
    <p>I have a few apps in my project that I want to be reusable.</p> <p>First, I have a base content App, which defines how content can be added to a ContentContainer. This allows other models to inherit ContentContainer to get the ability to show content.</p> <p>Within the content app, I have a Page model that inherits ContentContainer. In another app called events, I have an Event model that also inherites ContentContainer. Basically, my events app depends on my content app (Which is what I want).</p> <p>This all works great in modeling. I have this in my content app:</p> <pre><code>class ContentContainer(admin.ModelAdmin): #No fields, it just gets referred to by ContentItem class Meta: ordering = ['modified'] class ContentItem(TimeStampedModel): name = models.CharField(max_length=1500) page_order = models.IntegerField() container = models.ForeignKey(ContentContainer, blank=True) #make inheritance know the model type objects = InheritanceManager() class Meta: ordering = [ 'page_order', 'modified', 'name'] def __unicode__(self): return self.name def render(self): return self.name class TextContent(ContentItem): text = models.CharField(max_length=5000000) def render(self): return '&lt;p&gt;%s&lt;/p&gt;' % self.text </code></pre> <p>Then in my Events app I do this:</p> <pre><code>class Event(AnnouncementBase, Addressable, ContentContainer): cost = CurrencyField(decimal_places=2, max_digits=10, blank=True, default=0.00) start_date = models.DateField(default = datetime.now().date()) start_time = models.TimeField(default = datetime.now().time()) end_date = models.DateField(blank=True, default=None, null = True) end_time = models.TimeField(blank=True, default=None, null = True) rsvp_deadline = models.DateTimeField(blank=True, default=None, null = True) class Meta: ordering = ['start_date', 'start_time', 'title'] </code></pre> <p>So now events can have content to render.</p> <p>Here's where things get confusing. I have a slew of inlines defined in admin.py in the content app. They work great there. Also, if I copy an paste them into admin.py in the events app they work there too.</p> <p>However, I don't want to duplicate code. I want to import the inlines from admin.py into events.py In contents admin.py I have this:</p> <pre><code>class TextContentInline(admin.TabularInline): model = models.TextContent extra = 1 class PageAdmin(ContainerAdmin): model = models.Page inlines = [LinkContentInline, TextContentInline] </code></pre> <p>There are a bunch of these inlines. How can I share them between my admin.py models? If I try to import them in the events admin.py I get an error that says "The model Page is already registered". I've tried about 5 different things I could think of an none of them work. I am wondering if there is no way to do this. Oh I'm using Django 1.3 too.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload