Le samedi 10 mai 2014 13:36:27 UTC+2, [email protected] 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 [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to