mbi / django-front

Django-front is a front-end editing Django application

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Supprt for saving into models

willmoy opened this issue · comments

Hi

This looks really neat and well put together. Our use case though is that we'd like to edit our own models with inline editing. Is this something you plan to support, or would be interested in?

I hope this is a reasonable place to ask.

Thanks

Will

Hi. I see what you mean, but this is probably not the intended goal for django-front.

Check out the apps listed here: https://www.djangopackages.com/grids/g/frontend-editing/ I'm pretty sure there are at least a few doing exactly what you want.

From what I can tell this is actually quite straightforward (few extra steps required). If you simply add your own model:

class ModelPlaceholder(models.Model):
    id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
    default_text = models.TextField(default="Default text")

Then on your own model instead of using charfield etc you use:

editable_text_field = models.OneToOneField(ModelPlaceholder, null=True)

When you create an instance you just create ModelPlaceholder instance first and use it:

m = ModelPlaceholder.objects.create(default_text="This is what will show up for default text!")
YourModel.objects.create(editable_text_field=m)

Then finally in your templates you would use:

{% front_edit "{{ object.editable_text_field.id }}" %}
   {{ object.editable_text_field.default_text }}
{% end_front_edit %}

Works well! Of course its some extra work to start retrieving the actual text values using key_for on the id field etc but it should be possible. Could probably just create another field on the ModelPlaceholder thats a foreignkey to the Placeholder model and set up some signals to fill it in after first save.