Inline master

2016-12-01 Thread Roberto Russi
I have 3 models:

class Products(models.Model):
brand = models.ForeignKey(
Brands,
verbose_name = "Brand",
)
code = models.CharField("Code",
max_length=25, 
)
descr = models.CharField("Description",
max_length=50, 
)

class Orders(models.Model):
brand = models.ForeignKey(
Brands,
verbose_name = "Brand",
null=True,
blank=True,
related_name="ord_brand"
)
ord_date = models.DateField("Date")
ord_numb = models.CharField("Number",
max_length=20,
unique_for_year="ord_date", 
)

class OrderRows(models.Model):
order = models.ForeignKey(
Orders,
verbose_name = "Order",
)
product = models.ForeignKey(
Products,
verbose_name = "Product",
)
price = models.DecimalField("Price",
max_digits = 11,
decimal_places=2,
)

In my Admins.py I have a ModelAdmin for Orders whit a Inline for OrderRows.

How can I filter the product queryset in OrderRows where brand=orders.brand?

-- 
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/f54aaba0-bb94-421a-8902-00c6a9f594dd%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


inline parent value

2016-12-01 Thread Roberto Russi
hi, I have 3 models:

class Orders(models.Model):
brand = models.ForeignKey(
Brands,
verbose_name = "Brand",
null=True,
blank=True,
related_name="ord_brand"
)
dateord = models.DateField("Date")
numbord = models.CharField("Number",
max_length=20,
unique_for_year="dateord", 
)

class OrderRows(models.Model):
order = models.ForeignKey(
Orders,
verbose_name = "Order",
)
product = models.ForeignKey(
Products,
verbose_name = "Product",
)
price = models.DecimalField("Price",
max_digits = 11,
decimal_places=2,
)

class Products(models.Model):
brand = models.ForeignKey(
Brands,
verbose_name = "Brand",
)
code = models.CharField("Code",
max_length=25, 
)
descr = models.CharField("Description",
max_length=50, 
)

In my admin.py I have a ModelForm for Orders and an Inline for OrderRow.
In the Inline I need filter product queryset for records where 
brand=orders.brand.

How can I do it?

-- 
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/3f1d5cc5-6485-4f90-b626-929dc6d0e353%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


form_invalid

2017-01-29 Thread Roberto Russi
I need get data from a form when submit is clicked even if data are 
invalid, inconplete or empty.
I try to override form_invalid in CreateView but it is never called and 
form_valid, obviously, only if data are valid.
Why form_invalid is never called? 

I have this test project with django 1.10.5 and python 3.5

models.py

class Demo(models.Model):
demo_descr = models.CharField("Description",
max_length=50, 
)
demo_code = models.CharField("Code",
max_length=5,
)

def __str__(self):
return self.demo_descr

class Meta:
verbose_name = "Test"
verbose_name_plural = "Tests"
ordering = ["demo_descr"]

views.py

class DemoForm(forms.ModelForm):
class Meta:
model = models.Demo
fields = ('demo_descr','demo_code')
   

class DemoCreateView(CreateView):
form_class = DemoForm
success_url = 'demo'
template_name = 'test_form.html'
model = models.Demo

def form_valid(self, form):
print('valid')
return CreateView.form_valid(self, form)

def form_invalid(self, form):
print('invalid')
return CreateView.form_invalid(self, form)

urls.py

url(r'^demo$', views.DemoCreateView.as_view(),  name='demo'),


test_form.html


{% csrf_token %}
{{ form.as_p }}



-- 
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/c4ab5b85-13cc-4569-aa0d-5ef4dd6911a4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: form_invalid

2017-01-29 Thread Roberto Russi
I have tried it but post method is called only if form is valid and not if 
there are mandatory field not filled. 


Il giorno domenica 29 gennaio 2017 18:30:50 UTC+1, Norberto Bensa ha 
scritto:
>
> https://ccbv.co.uk is your friend with class based views.
>
> I'd override post(self, request, *args, **kwargs), in request.POST, you'll 
> have your form's data (before it's validated). 
>
> HTH,
> Norberto
>
> 2017-01-29 9:10 GMT-03:00 Roberto Russi 
> >:
>
>> I need get data from a form when submit is clicked even if data are 
>> invalid, inconplete or empty.
>> I try to override form_invalid in CreateView but it is never called and 
>> form_valid, obviously, only if data are valid.
>> Why form_invalid is never called? 
>>
>> I have this test project with django 1.10.5 and python 3.5
>>
>> models.py
>>
>> class Demo(models.Model):
>> demo_descr = models.CharField("Description",
>> max_length=50, 
>> )
>> demo_code = models.CharField("Code",
>> max_length=5,
>> )
>>
>> def __str__(self):
>> return self.demo_descr
>> 
>> class Meta:
>> verbose_name = "Test"
>> verbose_name_plural = "Tests"
>> ordering = ["demo_descr"]
>>
>> views.py
>>
>> class DemoForm(forms.ModelForm):
>> class Meta:
>> model = models.Demo
>> fields = ('demo_descr','demo_code')
>>
>>
>> class DemoCreateView(CreateView):
>> form_class = DemoForm
>> success_url = 'demo'
>> template_name = 'test_form.html'
>> model = models.Demo
>>
>> def form_valid(self, form):
>> print('valid')
>> return CreateView.form_valid(self, form)
>>
>> def form_invalid(self, form):
>> print('invalid')
>> return CreateView.form_invalid(self, form)
>>
>> urls.py
>>
>> url(r'^demo$', views.DemoCreateView.as_view(),  name='demo'),
>>
>>
>> test_form.html
>>
>> 
>> {% csrf_token %}
>> {{ form.as_p }}
>> 
>> 
>>
>> -- 
>> 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...@googlegroups.com .
>> To post to this group, send email to django...@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/c4ab5b85-13cc-4569-aa0d-5ef4dd6911a4%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/django-users/c4ab5b85-13cc-4569-aa0d-5ef4dd6911a4%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>

-- 
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/1262e431-5210-4707-bea6-0e8d8813c33b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: form_invalid

2017-01-29 Thread Roberto Russi
But fields are required! I need to have a control over form also if 'save' 
button is clicked and required fields are not filled.

Il giorno domenica 29 gennaio 2017 20:26:10 UTC+1, Norberto Bensa ha 
scritto:
>
> Are you telling me the following doesn't work for you? 
>
> class DemoCreateView(CreateView): 
> ... 
> def post(self, request, *args, **kwargs): 
>print(request.POST) 
>return super().post(request, *args, **kwargs) 
> ... 
>
>
> Now, at the console: 
>
>
>  ['A3hHKM6Bs6NjJA996ALAsYPcYR7M3NWkzP4wcd6WUX1CEazC1dAK3aD1n8zl1aUU'], 
> 'demo_desc 
> r': [''], 'demo_code': ['']}> 
>
> ... 
>
> BTW, I had to add "blank=True, null=True" to your models, otherwise 
> the fields are marked as required and the browser does validate that. 
>
> HTH, 
> Norberto 
>
>
> 2017-01-29 15:54 GMT-03:00 Roberto Russi  >: 
> > 
> > I have tried it but post method is called only if form is valid and not 
> if there are mandatory field not filled. 
> > 
> > 
> > Il giorno domenica 29 gennaio 2017 18:30:50 UTC+1, Norberto Bensa ha 
> scritto: 
> >> 
> >> https://ccbv.co.uk is your friend with class based views. 
> >> 
> >> I'd override post(self, request, *args, **kwargs), in request.POST, 
> you'll have your form's data (before it's validated). 
> >> 
> >> HTH, 
> >> Norberto 
> >> 
> >> 2017-01-29 9:10 GMT-03:00 Roberto Russi : 
> >>> 
> >>> I need get data from a form when submit is clicked even if data are 
> invalid, inconplete or empty. 
> >>> I try to override form_invalid in CreateView but it is never called 
> and form_valid, obviously, only if data are valid. 
> >>> Why form_invalid is never called? 
> >>> 
> >>> I have this test project with django 1.10.5 and python 3.5 
> >>> 
> >>> models.py 
> >>> 
> >>> class Demo(models.Model): 
> >>> demo_descr = models.CharField("Description", 
> >>> max_length=50, 
> >>> ) 
> >>> demo_code = models.CharField("Code", 
> >>> max_length=5, 
> >>> ) 
> >>> 
> >>> def __str__(self): 
> >>> return self.demo_descr 
> >>> 
> >>> class Meta: 
> >>> verbose_name = "Test" 
> >>> verbose_name_plural = "Tests" 
> >>> ordering = ["demo_descr"] 
> >>> 
> >>> views.py 
> >>> 
> >>> class DemoForm(forms.ModelForm): 
> >>> class Meta: 
> >>> model = models.Demo 
> >>> fields = ('demo_descr','demo_code') 
> >>> 
> >>> 
> >>> class DemoCreateView(CreateView): 
> >>> form_class = DemoForm 
> >>> success_url = 'demo' 
> >>> template_name = 'test_form.html' 
> >>> model = models.Demo 
> >>> 
> >>> def form_valid(self, form): 
> >>> print('valid') 
> >>> return CreateView.form_valid(self, form) 
> >>> 
> >>> def form_invalid(self, form): 
> >>> print('invalid') 
> >>> return CreateView.form_invalid(self, form) 
> >>> 
> >>> urls.py 
> >>> 
> >>> url(r'^demo$', views.DemoCreateView.as_view(),  name='demo'), 
> >>> 
> >>> 
> >>> test_form.html 
> >>> 
> >>>  
> >>> {% csrf_token %} 
> >>> {{ form.as_p }} 
> >>>  
> >>>  
> >>> 
> >>> -- 
> >>> 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...@googlegroups.com. 
> >>> To post to this group, send email to django...@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/c4ab5b85-13cc-4569-aa0d-5ef4dd6911a4%40googlegroups.com.
>  
>
> >>> For more options, visit https://groups.google.com/d/optout. 
> >> 
> >> 
> > -- 
> > 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...@googlegroups.com . 
> > To post to this group, send email to django...@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/1262e431-5210-4707-bea6-0e8d8813c33b%40googlegroups.com.
>  
>
> > 
> > For more options, visit https://groups.google.com/d/optout. 
>

-- 
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/59d268d9-269e-4875-a405-bc9c7985e506%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: form_invalid

2017-01-30 Thread Roberto Russi
Is just what i pictured. But when form_invalid is called?

Il giorno lunedì 30 gennaio 2017 02:35:54 UTC+1, Melvyn Sopacua ha scritto:
>
> On Sunday 29 January 2017 04:10:20 Roberto Russi wrote:
>
> > I need get data from a form when submit is clicked even if data are
>
> > invalid, inconplete or empty.
>
> > I try to override form_invalid in CreateView but it is never called
>
> > and form_valid, obviously, only if data are valid.
>
> > Why form_invalid is never called?
>
>  
>
> Because the form is blocked by client-side validation: it never gets to 
> the server. If you watch the development console closely, you will see that 
> when you press save, there is no incoming request.
>
>  
>
> Add the following clean method to DemoForm, fill in "bla" for demo_code in 
> the form and you will see form_invalid being called.
>
>  
>
> def clean(self):
> if self.data['demo_code'] != 'valid':
> raise ValidationError('{}: Invalid demo code'.format(
> self.data['demo_code']
> ))
>
> -- 
>
> Melvyn Sopacua
>

-- 
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/71fdcf25-d5ac-46a2-9e40-ce3eb3f3e1e3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


pre-populate new record foreing key in admin django-suit

2017-02-03 Thread Roberto Russi
I need to pre-populate some fields in the form opened when you press the 
plus button to add a new record for a foreingkey field in the admin 
interface.
I'm using Django-Suit. 

-- 
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/2085e2d4-e360-4fc7-b7bd-1418864bb0fc%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


validation of admin form with inlines

2017-02-04 Thread Roberto Russi
I need to validate a form in the admin area checking if the SUM of 'price' 
field in inlines match whit 'amount' field in the main form.

What is best way?   

-- 
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/da935043-5202-4a5f-aa99-b4b990559ce0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


In the admin area Pre-select foreingkey fields for filtered list

2017-02-08 Thread Roberto Russi
In the admin I have a list with a filter on a foreing-key field of model.
In the new record form, when the filter is applied, I wont that foreing-key 
field is pre-compiled with the same value of the filter.

Is there a way?

-- 
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/4507087d-3648-4960-adc2-cd19bf3dfae8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Add new record in filtered list in the admin interface

2017-02-26 Thread Roberto Russi
In the Admin interface when I add a new record to a filtered list and 
submits it, I come back in a no longer filtered list unlike when I edit a 
record.

How can I fix this problem?

-- 
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/db25fc45-ef27-403a-aff0-122dd08b67fe%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.