On Sun, May 11, 2014 at 10:14 AM, Stephen McDonald <st...@jupo.org> wrote:

> Great stuff.
>
> We (and most open source django apps that implement models) have this
> fundamental customization problem. Mezzanine has tried to solve it in
> different ways with EXTRA_MODEL_FIELDS and countless other bits of
> configuration throughout its apps, but I think the swappable model approach
> is spot on.  I also think this approach could be applied across more of
> Mezzanine - particularly the page model.
>
> Personally I haven't had the space to invest any time in this, so it's
> great to see this being done, and if you Hervé or anyone else has space for
> continuing it further, that'd be fantastic - I'm out of action over the
> next few weeks or so, but after then I'll hopefully be able to take a look
> at what's been done and bring it all into a new major version.
>
> Thanks again, and thanks for discussing it to begin with. Here are a few
> quick notes on the code so far:
>
> - Given the idea of applying this to other areas, we probably use a
> "get_post_model()" function, instead opting for something like
> "get_swappable_model()" which could live in mezzanine.utils somewhere.
>
> - Prefer to have "BlogPost = get_post_model()" (or get_swappable_model())
> somewhere at the top of each module rather than calling "get_post_model()"
> all throughout the file - it's probably faster, and makes the code read
> more like we're dealing with a model class.
>
> - Don't think we need an abstract base model if we're using swappable
> models - one seems to make the other redundant.
>
>
And please forget this last point, I'm quite wrong - we need the abstract
model to define all the base things the custom model being used to swap
with would need to implement.



>
>
> On Sun, May 11, 2014 at 2:10 AM, <bors....@gmail.com> wrote:
>
>> Le samedi 10 mai 2014 13:36:27 UTC+2, bors...@gmail.com a écrit :
>>
>>> So a first step would be to add a "BLOG_POST_MODEL" setting, probably
>>> using the "swappable" API.
>>>
>>> But copy/pasting Mezzanine code is no fun and complicates maintenance. I
>>> thought of splitting BlogPost into BaseBlogPost (or AbstractBlogPost
>>> #namingthings) being a abstract model and just an empty BlogPost class.
>>>
>>> Hi again,
>>
>> I implemented this idea in a  branch:
>> https://github.com/bors-ltd/mezzanine/tree/swappable_blogpost
>>
>> And I managed to make a BlogPost model with a geometric field. But
>> there's a bit more work than expected.
>>
>> I had to override ADMIN_MENU_ORDER to list "theme.BlogPost" instead of
>> "blog.BlogPost".
>>
>> The setting "BLOG_POST_MODEL" with BlogPost being swappable is working
>> like a charm. I added a get_post_model for places where BlogPost was
>> hard-coded.
>>
>> Here is my BlogPost model:
>>
>> class BlogPostManager(DisplayableManager, gis_models.GeoManager):
>>     pass
>>
>>
>> class BlogPost(blog_models.AbstractBlogPost, gis_models.Model):
>>     location = gis_models.PointField(verbose_name="Location", null=True)
>>
>>     objects = BlogPostManager()
>>
>> The admin:
>>
>> blogpost_fieldsets = deepcopy(blog_admin.blogpost_fieldsets)
>> blogpost_fieldsets.insert(1, ("Location", {"fields": ("location",)}))
>>
>>
>> class BlogPostAdmin(blog_admin.BlogPostAdmin, admin.OSMGeoAdmin):
>>     fieldsets = blogpost_fieldsets
>>
>>     map_width = 925
>>     map_height = 457
>>
>> The migration is a bit tricky, to pick up the existing posts:
>>
>>     def forwards(self, orm):
>>         db.rename_table("blog_blogpost", "theme_blogpost")
>>         db.rename_table("blog_blogpost_categories",
>> "theme_blogpost_categories")
>>         db.rename_table("blog_blogpost_related_posts",
>> "theme_blogpost_related_posts")
>>
>>         db.rename_index("blog_blogpost_pkey", "theme_blogpost_pkey")
>>         db.rename_index("blog_blogpost_site_id", "theme_blogpost_site_id")
>>         db.rename_index("blog_blogpost_user_id", "theme_blogpost_user_id")
>>
>> Then another migration to add extra fields:
>>
>>     def forwards(self, orm):
>>         # Adding field 'BlogPost.location'
>>         db.add_column('theme_blogpost', 'location',
>>                       self.gf
>> ('django.contrib.gis.db.models.fields.PointField')(null=True),
>>                       keep_default=False)
>>
>> So what do you think?
>>
>> --
>> 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 mezzanine-users+unsubscr...@googlegroups.com.
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
>
> --
> Stephen McDonald
> http://jupo.org
>



-- 
Stephen McDonald
http://jupo.org

-- 
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 mezzanine-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to