oscarmlage / django-cruds-adminlte

django-cruds is simple drop-in django app that creates CRUD for faster prototyping
BSD 3-Clause "New" or "Revised" License
424 stars 81 forks source link

Create and add inlines in 'same' time #121

Open hbrunacci opened 4 years ago

hbrunacci commented 4 years ago

hi, To be able to load data in the inline at the same time, I created an item I did this little trick. Is it ok or can it bring another complication? Basically what it does is forward to 'edit' url instead of 'list' url before success.


def get_create_view(self):
        CreateViewClass = super(Orden_TrabajoCRUD, self).get_create_view()

        class CreateView(CreateViewClass):
            inlines = self.inlines

            def get_success_url(self):
                url = super(CreateView, self).get_success_url()
                if self.inlines:
                    url_list = url.split('/')
                    url_list[url_list.index('list')] = str(self.object.id)
                    url = '/'.join(url_list) + '/update'
                return url

        return CreateView
oscarmlage commented 4 years ago

Apart from the hardcoded Orden_TrabajoCRUD reference, the code seems to be correct but I need some context to test it and see if it can be added as feature. A new setting that let the user choose between edit or list as the success_url would be nice.