Gotcha, I think I'm understanding better what you want to do.
I'm not sure this is possible because presumably the Slide class will need
a foreignkey to the parent page class that it shows up on, is that
correct? I.e. wouldn't the models really look something like this:
class SliderPage(Page):
pass
class Slide(Orderable):
sliderpage = models.ForeignKey(SliderPage, related_name="slides")
image = FileField(...)
Then wherever you had an instance of a SliderPage you could do:
sliderpage.slides.all()
I don't know of any way to inherit a ForeignKey relationship (that of
course doesn't mean it's impossible).
Something else you may be able to do is use a generic foreignkey in some
way,
https://docs.djangoproject.com/en/1.7/ref/contrib/contenttypes/#generic-relations,
that would allow you to have a slide be related to any other model, but it
would also complicate things a lot more.
On Tue, Jan 27, 2015 at 5:50 PM, Avery Laird <[email protected]> wrote:
> Hi Josh,
>
> Thanks for the reply. I actually already use abstract models in many of my
> projects -- very useful feature! Maybe I should have explained my thinking
> a bit better. I was describing something more along the lines of the
> RichTextPage behaviour. I know the mechanics behind the scences of
> RichTextPage is actually more complicated than this, but the behavior that
> we see involves a page (eg, class Page(Page, RichTextPage) ) which inherits
> RichTextPage. Is it possible to do something like that? For example, I know
> I also want my page to have a slider, so I do: class Page(Page, Slider).
> Let's say I also want an accordion: class Page(Page, Slider, Accordion).
> The level lower than *that *(BaseSlider, BaseAccordion) would involve
> the abstract models you talked about above. Being pretty new to django, I
> have some large gaps in my knowledge which may have prevented me from
> seeing some glaring error in this thinking -- is this even possible /
> practical?
>
> Thanks again, I appreciate your help with this!
>
> On Tue, Jan 27, 2015 at 7:58 AM, Josh Cartmell <[email protected]>
> wrote:
>
>> Hi Avery, you should be able to do this:
>>
>> class SlideBase(models.Model):
>> # eg
>> image = FileField(verbose_name=_("Image"),
>> upload_to=upload_to("theme.Slide.image", "slider"),
>> format="Image", max_length=255, null=True, blank=
>> True)
>> Class Meta:
>> abstract = True
>>
>>
>> Then:
>>
>> class Slider(Orderable, BaseSlider):
>> pass
>>
>> The key here is making BaseSlider abstract have a look at the docs if you
>> want to dive in more,
>> https://docs.djangoproject.com/en/1.7/topics/db/models/#abstract-base-classes
>>
>> On Mon, Jan 26, 2015 at 10:33 PM, Avery Laird <[email protected]>
>> wrote:
>>
>>> class Slider(Orderable):
>>> # eg
>>>
>>> image = FileField(verbose_name=_("Image"),
>>> upload_to=upload_to("theme.Slide.image", "slider"
>>> ),
>>> format="Image", max_length=255, null=True, blank=
>>> True)
>>> Class Meta:
>>> # whatever
>>>
>>>
>>
>> --
>> You received this message because you are subscribed to a topic in the
>> Google Groups "Mezzanine Users" group.
>> To unsubscribe from this topic, visit
>> https://groups.google.com/d/topic/mezzanine-users/HVAjvY2ZfCY/unsubscribe
>> .
>> To unsubscribe from this group and all its topics, send an email to
>> [email protected].
>> For more options, visit https://groups.google.com/d/optout.
>>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Mezzanine Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> For more options, visit https://groups.google.com/d/optout.
>
--
You received this message because you are subscribed to the Google Groups
"Mezzanine Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.