asifpy / django-crudbuilder

Generic CRUD implementation in Django
https://django-crudbuilder.readthedocs.org/en/latest/index.html
Apache License 2.0
193 stars 67 forks source link

Extend a view #9

Closed marcoshemann closed 8 years ago

marcoshemann commented 8 years ago

Hi Asif

I try extend the created view. ( from your example ) My app is : cadastro MY model is : Perfil

I want put in field criador the user ( request.user) ( I know that i can use signal to this, but is only a example) I created this view

class CadastroCrud(BaseCrudBuilder):
    model = Cadastro
    search_feilds = ['nome']    # é assim mesmo o nome
    tables2_fields = ('nome',  'sit')
    modelform_excludes = ['criador']
    login_required=True
    permission_required=False
    custom_modelform = CadastroForm

After I try extend :

from crudbuilder.views import ViewBuilder
builder = ViewBuilder('cadastro', 'Perfil', 'crud')   -> I don’t know what is the 3º parameter ( crud, crudclass, I get erro if I dont inform)
builder.generate_crud()
CadUpView = builder.classes['CadastroUpdateView']
class CustomCadUpView(CadUpView):
    def form_valid(self, form):
        print('form valid')
        form.instance.criador = self.request.user
        return super(CustomCadUpView, self).form_valid(form)

But I have no success

May you help-me with a example of extended CadastroUpdateView that send to forms aditional fields? like request.user, or request? Regards,

marcoshemann commented 8 years ago

crud field is obrigate to inform.

class BaseBuilder(object): def init( self, app, model, crud ):

asifpy commented 8 years ago

Its resolved here : https://github.com/asifpy/django-crudbuilder/commit/0c33661d4f6ba69b6f0c85de8e483a854730166f.

You check the example views: example/views.py