Re: Custom form fields in admin site

2016-09-09 Thread Luis Zárate
Hi,

I started to make a test project, and review the django code in options,
but I see the problem and started to code in other way  the result is in

https://github.com/luisza/onetooneForm

Now is more interesting because I try to provide a way to update onetoone
fields in the same form.  I made an elegant solution rewriting __new__
function of modelform, but I have son dudes about my implementation and I
really need to test it.  (Finished coding a few minutes ago)

In the REAME are the to issues that make me ask for help those are:

   - If I use RelToParentFrom in onetooneForm/forms.py works ok, but I
   wanted something like in onetooneForm/forms_wanted.py
   - No way to sort fields
   - How can I use formfield_callback? it's necesary





2016-09-09 2:01 GMT-06:00 ludovic coues :

> It's not easy to understand what you are trying to do and in which way it
> is failing. It would require us setting up a test project.
> I am assuming you want that the Admin display a form with a field for each
> of Mymodel field plus the myextra_field attribute and what you get is
> either only the name fields and maybe the myextra_field. If that not the
> case, plus give us more information about your problem.
>
> MymodelAdmin.fields is overriding MyForm.fields. If you are curious, it's
> around line 594 of django/contrib/admin/options.py. If fields is set,
> get_fields return that. Else, it will return the form base_fields and the
> modeladmin readonly_fields.
>
>
>
> 2016-09-08 18:41 GMT+02:00 Luis Zárate :
>
>> Hi,  I am trying to do something like
>>
>>
>> class MyForm(forms.ModelForm):
>>  myextra_field = forms.IntegerField()
>>
>> class Meta:
>>   models = Mymodel
>>   fields = '__all__'
>>
>> class MymodelAdmin(admin.ModelAdmin):
>>   form = MyForm
>>   fields = ["name", 'myextra_field']
>>
>> def save(self, *args, **kwargs)
>> do something with myextra_field
>>
>>
>> I know that is possible to specify readonly_fields and fields works but
>> in readonly mode that is not what i want.
>>
>> So is there any way to have extra form fields in admin.ModelAdmin in edit
>> mode?
>>
>>
>>
>> --
>> "La utopía sirve para caminar" Fernando Birri
>>
>>
>> --
>> 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+unsubscr...@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/ms
>> gid/django-users/CAG%2B5VyNVmNPzjkd-9bV_j35%2BNn5PYdjvMzi6GQ
>> v%2BhaDFZLrbug%40mail.gmail.com
>> 
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
>
> --
>
> Cordialement, Coues Ludovic
> +336 148 743 42
>
> --
> 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+unsubscr...@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/CAEuG%2BTZHhNTu1MXqCq_YXNxbKqX5SjCXeH3VJvV8Me_
> zmXpLXw%40mail.gmail.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>



-- 
"La utopía sirve para caminar" Fernando Birri

-- 
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+unsubscr...@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/CAG%2B5VyOhBkVXfeOWEh0Y0mA3eHkUs%3DeEV1xaPqoDocE%2BW3uCDw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Custom form fields in admin site

2016-09-09 Thread ludovic coues
It's not easy to understand what you are trying to do and in which way it
is failing. It would require us setting up a test project.
I am assuming you want that the Admin display a form with a field for each
of Mymodel field plus the myextra_field attribute and what you get is
either only the name fields and maybe the myextra_field. If that not the
case, plus give us more information about your problem.

MymodelAdmin.fields is overriding MyForm.fields. If you are curious, it's
around line 594 of django/contrib/admin/options.py. If fields is set,
get_fields return that. Else, it will return the form base_fields and the
modeladmin readonly_fields.



2016-09-08 18:41 GMT+02:00 Luis Zárate :

> Hi,  I am trying to do something like
>
>
> class MyForm(forms.ModelForm):
>  myextra_field = forms.IntegerField()
>
> class Meta:
>   models = Mymodel
>   fields = '__all__'
>
> class MymodelAdmin(admin.ModelAdmin):
>   form = MyForm
>   fields = ["name", 'myextra_field']
>
> def save(self, *args, **kwargs)
> do something with myextra_field
>
>
> I know that is possible to specify readonly_fields and fields works but in
> readonly mode that is not what i want.
>
> So is there any way to have extra form fields in admin.ModelAdmin in edit
> mode?
>
>
>
> --
> "La utopía sirve para caminar" Fernando Birri
>
>
> --
> 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+unsubscr...@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/ms
> gid/django-users/CAG%2B5VyNVmNPzjkd-9bV_j35%2BNn5PYdjvMzi6GQ
> v%2BhaDFZLrbug%40mail.gmail.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>



-- 

Cordialement, Coues Ludovic
+336 148 743 42

-- 
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+unsubscr...@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/CAEuG%2BTZHhNTu1MXqCq_YXNxbKqX5SjCXeH3VJvV8Me_zmXpLXw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Custom form fields in admin site

2016-09-08 Thread Luis Zárate
Hi,  I am trying to do something like


class MyForm(forms.ModelForm):
 myextra_field = forms.IntegerField()

class Meta:
  models = Mymodel
  fields = '__all__'

class MymodelAdmin(admin.ModelAdmin):
  form = MyForm
  fields = ["name", 'myextra_field']

def save(self, *args, **kwargs)
do something with myextra_field


I know that is possible to specify readonly_fields and fields works but in
readonly mode that is not what i want.

So is there any way to have extra form fields in admin.ModelAdmin in edit
mode?



-- 
"La utopía sirve para caminar" Fernando Birri

-- 
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+unsubscr...@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/CAG%2B5VyNVmNPzjkd-9bV_j35%2BNn5PYdjvMzi6GQv%2BhaDFZLrbug%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.