Tuesday, July 17, 2018

Help with reusing generic views in my little finance/budget application

I have a small checkbook application I am building as a hobby to replace my excel spreadsheets and learn Django and Python.  I am using Django 2 and Python 3 dot something.


I have 1 view (function) where your monthly income and expenses are displayed on an HTML Calendar.  The navigation is by month - basically my own pagination by month.


I have another view (function) - also by month that shows income and expenses in a table view.  More like you would see in Excel or a checkbook register.


Both views are using generic add, update, and delete class views.


class CheckCreate(CreateView):

    form_class = CheckForm

    model = Check

    success_url = reverse_lazy('checkbook-month')


class CheckUpdate(UpdateView):

    model = Check

    success_url = reverse_lazy('calendar')

    fields = ['dater', 'type', 'category', 'name', 'amount', 'cleared']

    template_name_suffix = '_update_form'


class CheckDelete(DeleteView):

    model = Check

    success_url = reverse_lazy('checkbook-month')


I would like to be able to render the generic views from either functional view and then get back to the view when the form is updated.  Right now I have to pick only 1 via the success_url.


Eventually, I would like to get back to the view at the right page too, but that is a stretch story at this point.


Now I think I know how to do this, but the implementation is somewhat sad.  I can create 2 forms that are identical and 2 views - lets say calendarUpdate and ListUpdate.  They would be identical, but at least I could manage the URL paths appropriately. Of course I would have to do this with the add and delete too and at some point it become rather silly. 


Additionally, I could then pass the month and year to the form, but right now that is a bit beyond my pay grade - thus the stretch story…


My way seems pretty clunky and I am looking for advice or a nudge in the right direction.  My Google searches come up short and usually are with some older version of Django and Python


Thanks.  rod


And my code is here.   Just posting for grins for for another newbie that wants to see a checkbook application.  It works, but probably not too impressive for the more advanced contributors.  I am working on commenting the heck out of it for other newbies like me.  https://github.com/rodtermaat/fmlDjango

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/ca7b28ba-bee6-47a1-ba69-ac50d9d3e3ce%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment