inline formset data not save

2021-09-11 Thread Anirban Singha
models.py

class product_list(models.Model):
   date=models.DateTimeField(auto_now_add=True,null=True)
   deal=models.ForeignKey(dealForm, null=True, blank=True , on_delete
=models.CASCADE)
   pro_name=models.ForeignKey(wareForm, null=True, on_delete=models.CASCADE)
   pro_quantity=models.IntegerField()
   def __str__(self):
 return self.name


forms.py 

class productForm(ModelForm):
   class Meta: 
 model=product_list
 fields= '__all__'

views.py
def myproduct(request, pk):
   x=wareForm.objects.all()
   DeliveryFormSet=inlineformset_factory(dealForm, product_list, fields=(
'pro_name','pro_quantity'), extra=len(x), can_delete=False)
   dealer=dealForm.objects.get(id=pk)
   formset=DeliveryFormSet(queryset= product_list.objects.none() , instance
=dealer)
   #date=datetime.datetime.now().strftime("%d-%m-%y")
   if request.method == 'POST':
 formset=DeliveryFormSet(request.POST,instance=dealer)
 print(formset)
 if formset.is_valid():
   for f in formset:
 print ('testing')
   return HttpResponseRedirect('delivery.html')
 else:
   print('hello')
context={'name':'Product list','formset':formset}
return render(request, 'product.html',context)

in this code formset.isvalid is false. BTW i'm beginner

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/ce0b66d1-bece-4c25-9f78-fda2909fe1d7n%40googlegroups.com.


Re: Inline Formset

2020-09-20 Thread Gabriel Araya Garcia
I believe that there is not other way to do this with AJAX. This is
an asynchronous call to database server. This not refresh your html
bye

Gabriel Araya Garcia
GMI - Desarrollo de Sistemas Informáticos




El vie., 18 sept. 2020 a las 1:49, Emmanuel Oppong Ntiamoah (<
ladamo...@gmail.com>) escribió:

> Good day friends, Please i have a small challenge, I have an inline
> formset in my admin where users can add more products to a store. The user
> can also add a product if It doesn’t already exist. The problem is when the
> user adds a new product and wants to add more product fields to the Store
> model the product the user added doesn’t show in the dropdown of the new
> field unless i refresh the whole interface.  Please any way to fix this.
> Thanks
>
> From Ntiamoah
>
> --
> 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 view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/8F6B832D-E616-4330-B7FE-EA3E9C4A6CF6%40gmail.com
> .
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAKVvSDCZzwFzhb99_QQUYHd_gQk1V3kDM%3D1QRMgeTYB52Hb5Hg%40mail.gmail.com.


Re: Inline Formset

2020-09-19 Thread coolguy
Please share some code so we can look into.

On Friday, September 18, 2020 at 12:50:49 AM UTC-4 lada...@gmail.com wrote:

> Good day friends, Please i have a small challenge, I have an inline 
> formset in my admin where users can add more products to a store. The user 
> can also add a product if It doesn’t already exist. The problem is when the 
> user adds a new product and wants to add more product fields to the Store 
> model the product the user added doesn’t show in the dropdown of the new 
> field unless i refresh the whole interface. Please any way to fix this. 
> Thanks
>
> From Ntiamoah 
>
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/5bbf293f-a9fb-4bfd-b3d3-745e1ee2486fn%40googlegroups.com.


Inline Formset

2020-09-17 Thread Emmanuel Oppong Ntiamoah
Good day friends, Please i have a small challenge, I have an inline formset in 
my admin where users can add more products to a store. The user can also add a 
product if It doesn’t already exist. The problem is when the user adds a new 
product and wants to add more product fields to the Store model the product the 
user added doesn’t show in the dropdown of the new field unless i refresh the 
whole interface.  Please any way to fix this.  
Thanks

>From Ntiamoah 

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/8F6B832D-E616-4330-B7FE-EA3E9C4A6CF6%40gmail.com.


m2m field widget to add or update data as inline formset

2020-01-28 Thread Suraj
Hello everyone,

This may be quite simple, but I am unable to find a widget which will 
function same as m2m widget of django, but will also create new model 
instance if it doesn't exists.

E.g.
If I had models as:
class Outcome(models.Model):
outcome = models.CharField(max_length=255)
outcome_short_name = models.CharField(max_length=10, blank=True, null=
True)


class Course(models.Model):
course_title = models.CharField(
verbose_name=COURSE_SINGULAR + " title", max_length=200, unique=True
)

course_outcome = models.ManyToManyField(
Outcome, verbose_name=COURSE_SINGULAR + " outcome", blank=True
)

Then I want "Outcomes" shown as below while creating course:

[image: Screenshot from 2020-01-28 15-05-09.png]


Now, If the outcomes data added by user already exists, then it should only 
map them to course. Otherwise it should first store outcomes into database 
and then map them to course.


Any guidance in right direction will be highly appreciated.

Thanks,

-- 
Suraj
https://hacksj4u.wordpress.com
https://github.com/SurajDadral

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/555a89e7-4ef7-4849-a9d5-032f7cafdac3%40googlegroups.com.


Inline formset for many to many relation

2020-01-24 Thread Suraj
Hello Everyone,

I want to inline formset for m2m relationship. Related code looks as 
follows:

models.py
```
class Outcome(models.Model):
# some fields
   # Foreign key is created to make outcomes inline in course form
   course_outcome = models.ForeignKey("course.Course", 
on_delete=models.SET_NULL, blank=True, null=True)

class Course(models.Model):
   # some fields
   course_outcome = models.ManyToManyField(Outcome, 
verbose_name=COURSE_SINGULAR + " outcome", blank=True)
```

forms.py
```
class OutcomeForm(forms.ModelForm):
   # some fields

class CourseForm(forms.ModelForm):
   # some fields including inline outcomes

OutcomeFormSet = 
inlineformset_factory(parent_model=Course, model=Outcome, form=OutcomeForm, 
extra=1, can_delete=True)
```

views.py
```
class CourseCreateForm(CreateView):
   model = Course
   template_name = "course/course_form.html"
   form_class = CourseForm
   success_url = reverse_lazy("course")

   def get_context_data(self, **kwargs):
  context = super(CourseCreateForm, self).get_context_data(**kwargs)
  if self.request.POST:
 context["outcomes"] = OutcomeFormSet(self.request.POST)
  else:
 context["outcomes"] = OutcomeFormSet()
  return context

   def form_valid(self, form, **kwargs):
  super(CourseCreateForm, self).get_context_data(**kwargs)
  context = self.get_context_data()
  outcomes = context["outcomes"]
  with transaction.atomic():
 if outcomes.is_valid():
self.object = form.save()
outcomes.instance = self.object
outcomes.save()
  
  
form.instance.course_outcome.set(Outcome.objects.filter(course_outcome=self.object))
form.save()
  return super().form_valid(form)
```

All my data in Outcome and Course models saved successfully except m2m 
field of course model.
Can anyone please guide me what I am doing wrong here.

Thanks in advance,

--
Suraj
https://hacksj4u.wordpress.com
https://github.com/SurajDadral

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/ef3447dc-b99d-41c7-968a-0e2d15275fee%40googlegroups.com.


Unable to save m2m field in Inline Formset with many to many relation in django CreateView

2020-01-24 Thread Suraj
Hello everyone,

I am unable to make it worked. I have two models "Course" and "Outcome". I 
want to make OutcomeForm form as inline form in CourseForm.

My models.py file looks as below:


class Outcome(models.Model):# some fields
course_outcome = models.ForeignKey(
"course.Course", on_delete=models.SET_NULL, blank=True, null=True)
class Course(models.Model):# some fields
course_outcome = models.ManyToManyField(
Outcome, verbose_name=COURSE_SINGULAR + " outcome", blank=True)


And inline formset is created as:


OutcomeFormSet = inlineformset_factory(
parent_model=Course,
model=Outcome,
form=OutcomeForm,
extra=1,
can_delete=True,)


And views.py file is:

class CourseCreateForm(CreateView):
model = Course
template_name = "course/course_form.html"
form_class = CourseForm
success_url = reverse_lazy("course")

def get_context_data(self, **kwargs):
context = super(CourseCreateForm, self).get_context_data(**kwargs)
if self.request.POST:
context["outcomes"] = OutcomeFormSet(self.request.POST)
else:
context["outcomes"] = OutcomeFormSet()
return context

def form_valid(self, form, **kwargs):
super(CourseCreateForm, self).get_context_data(**kwargs)
context = self.get_context_data()   
outcomes = context["outcomes"]
with transaction.atomic():
if outcomes.is_valid():
self.object = form.save()
outcomes.instance = self.object
outcomes.save()
form.instance.course_outcome.set(
Outcome.objects.filter(course_outcome=self.object)
)
form.save()
return super().form_valid(form)



The problem is:

All data of model Outcome and Course is saved except m2m field of Course 
model.

I am stuck at this point. Any pointer in right direction will be highly 
useful.

Thanks in advance,


--
Suraj
https://hacksj4u.wordpress.com
https://github.com/SurajDadral


-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/668f3879-1659-4867-867a-8f56e6996af0%40googlegroups.com.


Problem with UpdateView and inline formset

2016-08-17 Thread flaudizio
Hi evebody,

I'm using formset with inline and I can create the object in CreateView, 
but in UpdateView I get this error:

Erro:

ValidationError at /cadastros/pacientes/atualizar/7/
["'' value must be integer."]

django/db/models/fields/__init__.py in to_python:

Variable  | value
self
value   ''

---

I think the ID (main form) don't are passing through inline.

---
My codings:
---

View:

http://pastebin.com/KPG8SJF5

Forms.py:

TelefonePessoaFormSet = inlineformset_factory(Paciente, TelefonePessoa, 
fields=('tipo', 'numero',), extra=2, can_delete=True)

Thank's for all.

-- 
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/5556c40b-63d5-4c9b-ac67-5edd327c0963%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Django inline formset(UI) delete/remove

2015-05-11 Thread Ajay Kumar
I'm trying to do a inline formset with UI not with dajngo built in 
inlineformset_factory form.Here i'm done with add_view and edit_view.Here 
in the edit view i can update the existing record for the both parent and 
child model,and can add new record to the child model.But i cant remove the 
existing record from the child model in inline formset.Every thing is fine 
working at client side.When i click remove button from the UI, the record 
is removed by javascript,But in server side, in the edit_view the #Delete 
Existing record block cloud take the delete/remove functionality.I tried in 
many possible ways but i can't make the delete query for the removed items 
form the client side.

*models.py*

from django.db import models
class Category(models.Model):
name=   models.CharField(max_length=128)

def __unicode__(self):
return self.name
class Product(models.Model):
category=   models.ForeignKey(Category)
name=   models.CharField(max_length=128)
price   =   models.CharField(max_length=128)



views.py

def add(request):
context =  RequestContext(request)
if request.method == 'POST':
category = Category.objects.create(name = request.POST['category'])
try:
for n in range(1,7):
product = Product.objects.create(category= 
category,name=request.POST['name_'+str(n)],price=request.POST['price_'+str(n)])
except KeyError:
pass
return HttpResponseRedirect('/')
return render_to_response('add.html',context)
def edit(request,pk):
category = get_object_or_404(Category,id=pk)
product = Product.objects.filter(category=category)
product_count = product.count()
context =  RequestContext(request)
if request.method == 'POST':
for c in Category.objects.filter(id = category.id):
c.name = request.POST['category']
c.save()
try:
#Update Existing record(child)
for p,n in zip(Product.objects.filter(category = c),range(1,7)):
p.name = request.POST['name_'+str(n)]
p.price = request.POST['price_'+str(n)]
p.save()
except KeyError:
#Delete Existing record(child)
try:
for d in range(1,7):
for i in 
Product.objects.all().filter(name=request.POST.get('name_'+str(d)),price=request.POST.get('price_'+str(d))):
print i.name

except KeyError:
pass
else:
#Add new record(child)
try:
for r in range(1,7):
product,created = 
Product.objects.update_or_create(category= 
category,name=request.POST['name_'+str(r)],price=request.POST['price_'+str(r)])
except KeyError:
pass
return HttpResponseRedirect('/')
args = {'category':category,'product':product,'product_count':product_count}
return render_to_response('edit.html',args,context)




add.html

Add
var i = 1;
function addProduct(){
if (i <= 5){
i++;
var div = document.createElement('div');
div.innerHTML = 'Name:<input type="text" name="name_'+i+'" 
>Price:<input type="text" name="price_'+i+'" ><input type="button" value="-" 
onclick="removeProduct(this)">';
document.getElementById('products').appendChild(div);
}}

function removeProduct(div) {   
document.getElementById('products').removeChild( div.parentNode );
i--;}
{% csrf_token %}
Category



Product

(limit 6)
Name:Price:









edit.html

Edit
var i = {{product_count}};

function addProduct(){
if (i <= 5){
i++;
var div = document.createElement('div');
div.innerHTML = 'Name:<input type="text" name="name_'+i+'" 
>Price:<input type="text" name="price_'+i+'" ><input type="button" value="-" 
onclick="removeProduct(this)">';
document.getElementById('products').appendChild(div);
}}

function removeProduct(div) {   
document.getElementById('products').removeChild( div.parentNode );
i--;}
{% csrf_token %}
Category



Product



(limit 6)
{% for list in product %}

Name:Price:

{% endfor %}







<https://lh3.googleusercontent.com/-P8B0i2ViW-U/VVBnkHnMO6I/AY0/bPdQJ-qA6VM/s1600/Screenshot%2Bfrom%2B2015-05-11%2B13%3A35%3A06.png>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receivi

inlineformset_factory displays only inline formset, doesn't show parent model

2015-04-19 Thread Nkansah Rexford
I have this:

# consider all importations done right.

def add_noodle(request):NoodleFormSet = inlineformset_factory(Noodle, 
tutImages, form=NoodleForm, fields=('title', 'image'))if request.method 
== 'POST':formset = NoodleFormSet(request.POST, request.FILES)  
  if formset.is_valid():formset.save()else:formset 
= NoodleFormSet()return render_to_response('add_noodle.html', {
'formset': formset,})
I only get 3 tutImages model rendered in the template, without the Noodle 
model showing. I've been reading 
this: https://docs.djangoproject.com/en/dev/topics/forms/modelforms/ but 
don't seem to get what it means or what its trying to say with regards to 
the inlineformsets_factory.

I read the part 

> NoodleFormSet = inlineformset_factory(Noodle, tutImages, form=NoodleForm, 
> fields=('title', 'image'))


as

'Create an inline factory using tutImages Model (3 of them, alterable using 
> the extra=n param) under Noodle model, using NoodleForm (which tells it the 
> fields of Noodle model to expose to template)'


That doesn't work right. I'm missing something? Please help. Thanks


-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/7a5289a3-d5b6-419f-856a-32c9322fc1de%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django Inline formset with jquery

2015-02-17 Thread aRkadeFR

Hello,

I got the same kind of probleme while working on the formset
couple days ago.

If this is related, the problem is the auto complete javascript that
doesn't go well with the jquery.formset.js.

You can add a function "added" in parameter of the formset function
for reloading the autocomplete widget.

something like:
```
|
$(function() {
$(".inline.{{ orderformset.prefix }}").formset({
prefix: "{{ orderformset.prefix }}",
added: function () { reload_auto_complete(); },
})
})
|
```

About the deletion, is it on the front end or the backend you're
talking about?

If this is front -> check your javascript
If this is backend -> check all the values dumping request.POST

Hope I was useful


On 02/17/2015 06:01 AM, Ajay Kumar wrote:
Here by choosing serial_no and the rest of the fields name and author 
should be auto populate. Auto populate works for first inline formset 
and able to save it but when I add another inline formset auto 
populate is not working plus I'm unable to delete it or save 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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/54E2FF5F.2070509%40arkade.info.
For more options, visit https://groups.google.com/d/optout.


Django Inline formset with jquery

2015-02-16 Thread Ajay Kumar


Hello all,

I'm trying to build this following link feature in django, 
http://demo.smarttutorials.net/jquery-autocomplete/

Here by choosing serial_no and the rest of the fields name and author 
should be auto populate. Auto populate works for first inline formset and 
able to save it but when I add another inline formset auto populate is not 
working plus I'm unable to delete it or save it.

models.py
from django.db import models
class Book(models.Model):
serial_no = models.IntegerField(max_length = 100, unique = True)
name = models.CharField(max_length = 50)
author = models.CharField(max_length = 50)

def __unicode__(self):
return self.name

class CustomerOrder(models.Model):
name = models.CharField(max_length=256)

def __unicode__(self):
return self.name

class Order(models.Model):
customer  =  models.ForeignKey(CustomerOrder)
serial_no = models.IntegerField(max_length = 100, unique = True)
name = models.CharField(max_length = 50)
author = models.CharField(max_length = 50)
quantity = models.IntegerField(max_length = 100)

def __unicode__(self):
return self.name


forms.py

from django import forms
from bookapp.models import CustomerOrder


class CustomerOrderForm(forms.ModelForm):
class Meta:
model = CustomerOrder
exclude = ('customer',)


views.py

from django.http import HttpResponse
from django.shortcuts import render
from bookapp.models import *
from bookapp.forms import CustomerOrderForm
import json
from django.core.exceptions import ObjectDoesNotExist
from django.http import HttpResponseRedirect
from django.template import RequestContext
from django.core.context_processors import csrf
from django.shortcuts import render_to_response, get_object_or_404
from django.forms.models import inlineformset_factory


def home(request):
context =  RequestContext(request)
OrderFormSet =   inlineformset_factory(CustomerOrder, Order  ,extra=1, 
exclude=('customer',))
if request.method == "POST":
customerorderform = CustomerOrderForm(request.POST)
orderformset = OrderFormSet(request.POST)
if customerorderform.is_valid() and orderformset.is_valid():
a = customerorderform.save()
orderformset.save(commit=False)
orderformset.instance = a
orderformset.save()
return HttpResponse('Added')
else:
customerorderform = CustomerOrderForm()
orderformset = OrderFormSet()
for orderform in orderformset:
orderform.fields['serial_no'].widget.attrs = {'id' : 'sno', 
'onkeydown':"myFunction()"}
orderform.fields['name'].widget.attrs = {'id' : 'bname'}
orderform.fields['author'].widget.attrs = {'id' : 'bauthor'}

args = {}
args.update(csrf(request))
args = {'customerorderform':customerorderform, 'orderformset':orderformset}
return render_to_response('home.html',args,context)

def fetch_serial_nos(request):
serial_nos = map(lambda x: str(x.serial_no), Book.objects.all())
return HttpResponse(content = json.dumps({'serial_nos': serial_nos}), 
content_type = "application/json; charset=UTF-8")

def get_entry_corresponds_to_serial_no(request):
serial_no = request.GET['serial_no']
try: 
entry = Book.objects.get(serial_no=int(serial_no))
data = {'name': entry.name, 'author': entry.author}
except (ObjectDoesNotExist, ValueError):
data = {'name': '', 'author': ''}
return HttpResponse(content = json.dumps(data), content_type = 
"application/json; charset=UTF-8")


home.html




Enter S.NO

$(function() {
$(".inline.{{ orderformset.prefix }}").formset({
prefix: "{{ orderformset.prefix }}",
})
})



Orders
{% csrf_token %}

Customer
{{customerorderform}}

   
Order
{{ orderformset.management_form }}
{{ orderformset.non_form_errors }}
{% for form in orderformset %}
{{ form.id }}

{{form}}

{% endfor %}









$(function(){
$.ajax({
type: "GET",
url: '/serial_nos/',
success: function (response) {
serial_nos = response['serial_nos'];
$( "#sno" ).autocomplete({
source: serial_nos
 });
},
});   
});
function myFunction(){ 
var sno = document.getElementById("sno").value;
console.log(sno)
document.getElementById("demo").innerHTML = "You selected: " + sno;
$.ajax({
type: "GET",
url: '/entry/',
data : {
serial_no : sno,
},
success:

Re: CBV with inline formset

2014-12-15 Thread Brad Rice
Thanks. I think I figured out how to do this with a straight createView.

class BookCreate(CreateView):
model = Book
form_class = BookForm
template_name = 'book_template.html'
success_url = u'/dp/thanks'

def get(self, request, *args, **kwargs):
self.object = None
form_class = self.get_form_class()
author = Author.objects.get(id=self.kwargs['author_id'])
formset = BookFormset(instance=author)
return self.render_to_response(self.get_context_data(formset=formset))

def post(self, request, *args, **kwargs):
self.object = None
form_class = self.get_form_class()
author = Author.objects.get(id=self.kwargs['author_id'])
formset = BookFormset(request.POST,request.FILES,instance=author)
if formset.is_valid():
formset.save()
return HttpResponseRedirect(reverse('dp:thanks'))

def form_valid(self, formset):
context = self.get_context_data()
book_formset = context['formset']
if book_formset.is_valid():
# self.object = book_formset.save()
book_formset.instance = self.object
book_formset.save()
return HttpResponseRedirect(self.get_success_url())
else:
return 
self.render_to_response(self.get_context_data(formset=book_formset))

On Monday, December 15, 2014 4:09:29 PM UTC-5, Vijay Khemlani wrote:
>
> Try changing the name of the parameter in the url from author_id to pk
>
> On Mon, Dec 15, 2014 at 5:39 PM, Brad Rice <brad...@gmail.com 
> > wrote:
>>
>> I've pretty much butchered the code for 3 days now and cannot figure out 
>> how to insert an inline formset. Can anybody help me?
>>
>> I've tried to pare everything down to use two simple Models just to try 
>> to get an insert. I'm using django Author - Book relationship to keep it 
>> simple.
>>
>> class Author(models.Model):
>> name = models.CharField(max_length=100)
>>
>> def __unicode__(self):  # __unicode__ on Python 2
>> return self.name
>>
>>
>> class Book(models.Model):
>> name = models.CharField(max_length=100)
>> author = models.ForeignKey(Author)
>>
>> So I have a page where you can insert and author. The author page takes 
>> you to a page to insert books for that author using an inline formset of 3 
>> books.
>>
>> In my urls.py I have this url url(r'^book_create/(?P\d+)/$', 
>> BookCreate.as_view(), name='book_create'),
>>
>> When you go to book_create I can see the author_id getting passed in the 
>> kwargs. Now how to I insert from there books into the db with the Foreign 
>> Key to that author passed in the kwargs?
>>
>> After banging away for so long, I decided to try to switch to django 
>> extra views. this is what I have in my views.py
>>
>> class BookCreate(InlineFormSetView):
>> model = Author
>> inline_model = Book
>> form_class = BookForm
>> extra = 3
>> template_name = 'book_template.html'
>>
>> def get_queryset(self):
>> slug = self.kwargs['author_id']
>> return super(BookCreate, self).get_queryset().filter(id=slug)
>>
>> When I go to the book_create page I get this error:
>>
>> Generic detail view BookCreate must be called with either an object pk or a 
>> slug.
>>
>>  -- 
>> 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 http://groups.google.com/group/django-users.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/df120546-0931-4b17-93e1-70ba884e62f5%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/django-users/df120546-0931-4b17-93e1-70ba884e62f5%40googlegroups.com?utm_medium=email_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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/d3e56823-8b3d-45b7-8815-2c444bec75b8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: CBV with inline formset

2014-12-15 Thread Dan Gentry
I created a couple of mixins for a project that might help you.  See this 
gist: https://gist.github.com/dashdrum/03858d79ddfd9bba44d6

Pretty easy to use.  Here's an example Create view:

class RegistrationView(FormsetCreateMixin,CreateView):
template_name = 'registration/registration_form.html'
model = RegistrationMaster
form_class = RegistrationForm
detail_form_class = RegDetailFormSet


The mixin creates a new class variable: detail_form_class.  Set this in the 
view class declaration to point to your formset.  

I haven't tested this beyond the one project, so please tread carefully.  I 
hope this can at least get you moving in the right direction.



-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/e4ddc6d2-b38d-4308-a424-949ebeb39996%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: CBV with inline formset

2014-12-15 Thread Vijay Khemlani
Try changing the name of the parameter in the url from author_id to pk

On Mon, Dec 15, 2014 at 5:39 PM, Brad Rice <bradri...@gmail.com> wrote:
>
> I've pretty much butchered the code for 3 days now and cannot figure out
> how to insert an inline formset. Can anybody help me?
>
> I've tried to pare everything down to use two simple Models just to try to
> get an insert. I'm using django Author - Book relationship to keep it
> simple.
>
> class Author(models.Model):
> name = models.CharField(max_length=100)
>
> def __unicode__(self):  # __unicode__ on Python 2
> return self.name
>
>
> class Book(models.Model):
> name = models.CharField(max_length=100)
> author = models.ForeignKey(Author)
>
> So I have a page where you can insert and author. The author page takes
> you to a page to insert books for that author using an inline formset of 3
> books.
>
> In my urls.py I have this url url(r'^book_create/(?P\d+)/$',
> BookCreate.as_view(), name='book_create'),
>
> When you go to book_create I can see the author_id getting passed in the
> kwargs. Now how to I insert from there books into the db with the Foreign
> Key to that author passed in the kwargs?
>
> After banging away for so long, I decided to try to switch to django extra
> views. this is what I have in my views.py
>
> class BookCreate(InlineFormSetView):
> model = Author
> inline_model = Book
> form_class = BookForm
> extra = 3
> template_name = 'book_template.html'
>
> def get_queryset(self):
> slug = self.kwargs['author_id']
> return super(BookCreate, self).get_queryset().filter(id=slug)
>
> When I go to the book_create page I get this error:
>
> Generic detail view BookCreate must be called with either an object pk or a 
> slug.
>
>  --
> 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 http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/df120546-0931-4b17-93e1-70ba884e62f5%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/df120546-0931-4b17-93e1-70ba884e62f5%40googlegroups.com?utm_medium=email_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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CALn3ei17tEEDg9W5jvvcoAtp%3DN6XnDzGAxfkkAd8MQLA809RtQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


CBV with inline formset

2014-12-15 Thread Brad Rice
I've pretty much butchered the code for 3 days now and cannot figure out 
how to insert an inline formset. Can anybody help me?

I've tried to pare everything down to use two simple Models just to try to 
get an insert. I'm using django Author - Book relationship to keep it 
simple.

class Author(models.Model):
name = models.CharField(max_length=100)

def __unicode__(self):  # __unicode__ on Python 2
return self.name


class Book(models.Model):
name = models.CharField(max_length=100)
author = models.ForeignKey(Author)

So I have a page where you can insert and author. The author page takes you 
to a page to insert books for that author using an inline formset of 3 
books.

In my urls.py I have this url url(r'^book_create/(?P\d+)/$', 
BookCreate.as_view(), name='book_create'),

When you go to book_create I can see the author_id getting passed in the 
kwargs. Now how to I insert from there books into the db with the Foreign 
Key to that author passed in the kwargs?

After banging away for so long, I decided to try to switch to django extra 
views. this is what I have in my views.py

class BookCreate(InlineFormSetView):
model = Author
inline_model = Book
form_class = BookForm
extra = 3
template_name = 'book_template.html'

def get_queryset(self):
slug = self.kwargs['author_id']
return super(BookCreate, self).get_queryset().filter(id=slug)

When I go to the book_create page I get this error:

Generic detail view BookCreate must be called with either an object pk or a 
slug.

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/df120546-0931-4b17-93e1-70ba884e62f5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to edit a model with an inline formset

2014-01-10 Thread Brad Rice
I'm following that blog entry, too, and getting an error when I try to 
save: [u'ManagementForm data is missing or has been tampered with']

On Thursday, January 9, 2014 11:57:37 AM UTC-5, Cody Scott wrote:
>
> I am trying to create a model with an inline formset. I followed the guide 
> here 
> http://kevindias.com/writing/django-class-based-views-multiple-inline-formsets/
>
>
> Creating my model as in the guide works. But I am trying to edit my model. 
> The EditPage renders fine with the form but when I submit the form I get an 
> error on the {{ skill_form.management_form }} line in my template. list index 
> out of range.
>
>
> #modelsclass Job(models.Model):
> user = models.ForeignKey(settings.AUTH_USER_MODEL, related_name='jobs')
> title = models.CharField('job title', max_length=255)
> slug = models.SlugField(max_length=255, blank=True, default='')
> city = models.CharField(max_length=255)
> company = models.CharField(max_length=255)
> start_date = models.DateField()
> type = models.CharField("Work Shedule", max_length=255)
> remote = models.BooleanField("Remote Work")
> contact = models.TextField()
>
> description = models.TextField()
> requirements = models.TextField(null=True, blank=True)
> responsibilities = models.TextField(null=True, blank=True)
> education = models.TextField(null=True, blank=True)
> experience = models.TextField(null=True, blank=True)
> perks = models.TextField(null=True, blank=True)
> about = models.TextField("About the Company", null=True, blank=True)
>
> post_date = models.DateField(auto_now_add=True, editable=False)
> updated_date = models.DateTimeField(auto_now=True, editable=False)
>
> class Meta:
> ordering = ["-updated_date", "title"]
>
> def __unicode__(self):
> return self.title
>
> def save(self, *args, **kwargs):
> if not self.slug:
> self.slug = slugify(self.title)
> super(Job, self).save(*args, **kwargs)
>
> def get_absolute_url(self):
> return reverse('job:view', args=(), kwargs={'id': self.id, 'slug': 
> self.slug})
>
> class Skill(models.Model):
> job = models.ForeignKey(Job, related_name='skills')
> skill = models.CharField(max_length=255)
>
>
> def __unicode__(self):
> return self.skill
> #formsclass JobForm(forms.ModelForm):
> type = forms.ChoiceField(choices=[('Full-Time', 'Full-Time'), 
> ('Part-Time', 'Part-Time')])
>
> class Meta:
> model = Job
> fields = ['title', 'city', 'company', 'start_date', 'description',
>   'requirements', 'responsibilities', 'education', 'experience',
>   'perks', 'contact', 'remote', 'about']
>
> SkillFormSet = inlineformset_factory(Job, Skill)
>
> #viewsclass CreateJob(generic.CreateView):
> model = Job
> template_name = 'job/add.html'
> form_class = JobForm
>
> def get(self, request, *args, **kwargs):
> """instantiates blank versions of the formand its 
> inline formsets"""
> self.object = None
> form_class = self.get_form_class()
> form = self.get_form(form_class)
> skill_form = SkillFormSet()
> return self.render_to_response(self.get_context_data(
> form=form,
> skill_form=skill_form,
> ))
>
> def post(self, request, *args, **kwargs):
> """instantiates the form with its inline formsetswith 
> the passed POST data and validates"""
> self.object = None
> form_class = self.get_form_class()
> form = self.get_form(form_class)
> skill_form = SkillFormSet(self.request.POST)
> if form.is_valid() and skill_form.is_valid():
> return self.form_valid(form, skill_form)
> else:
> return self.form_invalid(form, skill_form)
>
> def form_valid(self, form, skill_form):
> """If both forms are valid then create Job with skills and 
> redirect"""
> self.object = form.save(commit=False)
> self.object.user = self.request.user
> self.object.save()
> skill_form.instance = self.object
> skill_form.save()
> return HttpResponseRedirect(self.object.get_absolute_url())
>
> def form_invalid(self, form, skill_form):
> """If either of the forms are invalidRe-render the 
> page with data-filled forms and errors"""
> 

Re: Inline formset with different default values for each "extra" row

2012-12-04 Thread Chris Cogdon
Because Lee Hinde's thread is broken, I'm going to take a punt at what the 
question is :)

in a formset (inline, model, or just a plain one), the "initial" parameter 
to the instantiation of the form takes an list of dictionaries. Each 
element in the list is the initial data for _that_ row... so if you want 5 
different part numbers, for example, do this.


formset = MyFormSet ( ..other params.., 
 
initial=[{'partno':10},{'partno':11},{'partno':12},{'partno':13},{'partno':14}] 
)

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/2gJzJTG-U_MJ.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Inline formset with different default values for each "extra" row

2012-12-04 Thread Lee Hinde
For a product up to three different vendors have been identified and I want
to present a row per vendor (which is a fk) so that the user could select
order quantities from each vendor.

If a vendor doesn't have an order quantity, I'd want to ignore it at
form.save() time, rather than reject it.

Pointers are appreciated.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Inline formset for django project

2012-05-15 Thread William Ibarra Rodriguez
H! i need a way to use a inlineformset in my app, anyone knows how to
use the inline tabular o stack formset of the admin site in an app??

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



inline formset error, help!!!

2012-05-07 Thread William Ibarra Rodriguez
i have a project in which i try to use the inline formset factory so
when i try to fill the form it throw the following error:

UnboundLocalError at /catalogo/adicionar/articulo/
local variable 'imagen_formset' referenced before assignment

in my view i had:

 if request.POST:
form = ArticuloForm(request.POST)

if form.is_valid():
articulo = form.save()
imagen_formset = ImagenesFormSet(request.POST,
instance = articulo)

if
imagen_formset.is_valid():
articulo.save()
imagen_formset.save()
return HttpResponseRedirect('/catalogo/
articulo/')
else:
form = ArticuloForm()
imagen_formset = ImagenesFormSet(instance =
Articulo())

return render_to_response("catalogo/articulo_form.html", {
"form": form,
"imagen_formset": imagen_formset,
}, context_instance=RequestContext(request))

my form is:

ImagenesFormSet = inlineformset_factory(Articulo,Imagenes)

class ArticuloForm(forms.ModelForm):
class Meta:
model = Articulo
def __init__(self, *args, **kwargs):
super(ArticuloForm, self).__init__(*args, **kwargs)


-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Validation error by working with inline formset

2012-05-03 Thread William Ibarra Rodriguez
In my django project I've working with inline formset factory to join
two forms, so when i try to edit the main form this error happens

ValidationError at /catalogo/editar/articulo/3/
 [u'ManagementForm data is missing or has been tampered with']

my models.py is:

class Articulo(models.Model):
titulo = models.CharField(max_length=50)
materiales = models.CharField(max_length=60)
manifestacion = models.ForeignKey(Manifestacion)
tecnica = models.ForeignKey(Tecnica)
dimension = models.CharField(max_length=20)
capacidad_productiva = models.PositiveIntegerField()
creador = models.ForeignKey(Creador)
grupo_creacion = models.ForeignKey(Grupo_Creacion, blank=True,
null=True)
precio = models.DecimalField(max_digits=10,decimal_places=2)
tematica = models.CharField(max_length=150)
calidad = models.CharField(max_length=50, choices =
calidad_choice)
fecha_creacion = models.DateField()

class Meta:
verbose_name_plural = "Gestionar Articulos"
verbose_name = "Articulo"
ordering = ['-id']
permissions = (("listar_articulo","Listar Articulo"),)

def __unicode__(self):
return '%s' % (self.titulo)
def __str__(self):
return '%s' % (self.titulo)

class Imagenes(models.Model):
imagen = models.ImageField(upload_to="uploads/")
dir_imagen = models.CharField(max_length=200)
principal = models.BooleanField()
articulo = models.ForeignKey(Articulo)

def __unicode__(self):
return '%s' % (self.imagen)
def __str__(self):
return '%s' % (self.imagen)

my forms.py is :

ImagenFormSet = inlineformset_factory(Articulo,Imagenes)

class ArticuloForm(forms.ModelForm):
class Meta:
model = Articulo

so in the views.py i had:

@csrf_protect
@login_required
def editar(request, model, key=None):
model_object = get_model('catalogo', model)
if model_object:
if model == "articulo":

articulo = Articulo.objects.get(pk=key)
ImagenFormSet = inlineformset_factory(Articulo, Imagenes)
if request.method == "POST":
imagen_formset = ImagenFormSet(request.POST,
request.FILES, instance = articulo)
if imagen_formset.is_valid():
imagen_formset.save()
else:
imagen_formset = ImagenFormSet(instance = articulo)
return update_object(request, model=model_object,
object_id=key,extra_context={"imagen_formset": imagen_formset},
post_save_redirect='/catalogo/%s/' % model)

return update_object(request, model=model_object,
object_id=key, post_save_redirect='/catalogo/%s/' % model)
else:
raise Http404()



-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Problem with a clean in inline formset

2012-05-01 Thread Ernesto Guevara
Solution:

def clean(self):
   if any(self.errors):
   # Don't bother validating the formset unless each form is
valid on its own
   return
   for i in range(0, self.total_form_count()):
   form = self.forms[i]
   cleaned_data = form.clean()
   display = cleaned_data.get('display', None)
   if cleaned_data['DELETE'] == False:
 if display.max_windows() >= display.windows:
   raise forms.ValidationError("The display have all
windows occupied.")

Put the line if cleaned_data['DELETE'] == False:  to check if the inline
have the attribute DELETE and if is false, to ignore deleted rows in
formset that have true in this attribute. =)

2012/4/30 Guevara <eguevara2...@gmail.com>

> Hello!
>
> The (if display.max_windows() >= display.windows) works fine to
> prevent insert. Behaves as expected.
> But is raised even when the row is REMOVED from the edit formset. =/
>
> ## Models
>
> class Display(models.Model):
>windows = models.IntegerField()
>
> def max_windows(self):
>total = self.window_set.all().count() #window is a
> intermediary class to campaign
>if total:
>return total
>
> ## Clean method in CampaignInlineFormSet
>
> def clean(self):
>if any(self.errors):
># Don't bother validating the formset unless each form is
> valid on its own
>return
>for i in range(0, self.total_form_count()):
>form = self.forms[i]
>cleaned_data = form.clean()
>display = cleaned_data.get('display', None)
>if display.max_windows() >= display.windows:
>raise forms.ValidationError("The display have all
> windows occupied.")
>
> This "if" can not stop me remove a row in inline formset. How can I
> fix this?
> Regards.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Problem with a clean in inline formset

2012-04-30 Thread Guevara
Hello!

The (if display.max_windows() >= display.windows) works fine to
prevent insert. Behaves as expected.
But is raised even when the row is REMOVED from the edit formset. =/

## Models

class Display(models.Model):
windows = models.IntegerField()

def max_windows(self):
total = self.window_set.all().count() #window is a
intermediary class to campaign
if total:
return total

## Clean method in CampaignInlineFormSet

def clean(self):
if any(self.errors):
# Don't bother validating the formset unless each form is
valid on its own
return
for i in range(0, self.total_form_count()):
form = self.forms[i]
cleaned_data = form.clean()
display = cleaned_data.get('display', None)
if display.max_windows() >= display.windows:
raise forms.ValidationError("The display have all
windows occupied.")

This "if" can not stop me remove a row in inline formset. How can I
fix this?
Regards.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Verifying number of forms in inline formset

2012-03-05 Thread Michael Stevens
Hi.

I've got a django app using an inline formset.

It was all working nicely, but I want to add some validation such that the 
inline formset must contain at least one valid record. This seems to be 
surprisingly hard to do.

I've tried overriding clean() on the formset and looking at things like 
self.form, is_valid(), and so on, but I can't work out anything that will 
let me know the number of database records that will be present when the 
formset is saved.

Am I missing anything obvious? How could I do this?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/wols1d5EPegJ.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Inline formset factory ignores 'exclude=' for foreign key field

2012-03-01 Thread gulrtosk
Right, I don't know whether this is a bug or done on purpose ... It looks 
like it was done on purpose so I'd be happy to hear the experts on this. 
I'm using Django 1.3. I hope I got this right.

On line 752 of django.forms.models (development trunk), in the add_fields() 
method of BaseInlineFormSet it says:

name = self.fk.name
...
form.fields[name] = InlineForeignKeyField(self.instance, **kwargs)

This is *after* all processing of 'fields=' and 'exclude=' kwargs has been 
done on the form. Consequently, for all inline form sets the foreign key 
field is always included. It is not possible to 'exclude=' it. Any opinions 
on why this should be so?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/ZBqnjPrqj80J.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Inline formset factory ignores 'exclude=' for foreign key field

2012-03-01 Thread gulrtosk
Hello list,

through trial and error I discovered that it isn't required to pass the 
foreign key form field post data to the constructor of an inline form set. 
Django will fill it in automatically by looking at the primary key of the 
'instance=' given. So I figured I might as well exclude the hidden FK field 
from the form:

class Group(models.Model):
interest = models.CharField(max_length=100)
class Member(models.Model):
name = models.CharField(max_length=100)
group = models.ForeignKey(Group)

MemberFormSet = inlineformset_factory(Group, Member, exclude=('group',))

The 'exclude=' instruction is ignored and the form is printed the same as 
without 'exclude=('group',)'. This is odd, since the FKs aren't strictly 
required in the form set: if you pass post data *with* foreign key fields 
to the constructor MemberFormSet(), Django will use it for validation, but 
if you don't pass them, it's fine too, because Django will simply use the 
instance to fill them in automatically.

So, how can I exclude my 'group' foreign keys from the printed form set?

Thank you and cheers, glts

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/msqQh54-X5oJ.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Form for inline formset

2011-08-27 Thread Marcos Moyano
Can someone please tell me how can I specify a form to be used by every form
inside an inline formset (if possible)?

Thanks in advance!
Marcos

-- 
Some people, when confronted with a problem, think “I know, I'll use regular
expressions.” Now they have two problems.

Jamie Zawinski, in comp.emacs.xemacs

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: How do I override default behaviour for foreign keys in an inline formset?

2011-05-29 Thread King
Though I originally asked for a "detailed solution", even some
suggestions as to what I should be googling would be helpful at this
point.  I know I'm not the only one to have tried to do this, so I
can't imagine someone doesn't have an answer somewhere.

On May 26, 12:43 am, King  wrote:
> I want to do something like 
> this...http://groups.google.com/group/django-users/browse_thread/thread/db03...
> ...but unfortunately there was no reply to this particular posting.
> I've found other posts on the web of people looking for the same sort
> of solution, and have not been able to find any helpful answers, so I
> was hoping someone here could clear this up.
>
> For example, let's say I had an app that kept a list of books for each
> user like this:
>
> class BookList(models.Model):
>     user = models.ForeignKey(User)
>     book = models.ForeignKey(Book)
>
> class Book(models.Model):
>     author = models.ForeignKey(Author)
>     name = models.CharField(max_length=300)
>
> class Author(models.Model):
>     name = models.CharField(max_length=300)
>
> I had thought that to generate a bunch of forms for BookList (so that
> the current user could for example, enter in all of the books that
> they've read on a single page), I would use an inlineformset like so:
>
> BookListFormSet = inlineformset_factory(User, BookList)
> booklist_formset = BookListFormSet(instance=currentUser)
>
> However, the resulting formset I get results in a dropdown menu for
> each book field in the forms, but I don't want that. I want two
> TextInput widgets in the form such that the user can type out:
>    Alice in Wonderland
>    Lewis Carroll
> and if some other user has already added "Alice in Wonderland" to
> their book list, then BookList.book will just point to that book.  BUT
> if this is the first user to add "Alice in Wonderland" to their book
> list, I want the form to create a brand new row in the Book table (and
> a brand new row in Author if there is no "Lewis Carroll" books yet
> either).
>
> I'm new to Django, so maybe the solution is obvious to many.  But like
> I said, I'm finding lots of people asking this question, but without
> any good answers posted.
>
> If someone could please provide a detailed solution I would very much
> appreciate it, and I imagine others would as well.
>
> Thanks in advance.  If any part of what I'm asking isn't clear, don't
> hesitate to ask me about it.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



How do I override default behaviour for foreign keys in an inline formset?

2011-05-25 Thread King
I want to do something like this...
http://groups.google.com/group/django-users/browse_thread/thread/db03fa90a14ecc6a
...but unfortunately there was no reply to this particular posting.
I've found other posts on the web of people looking for the same sort
of solution, and have not been able to find any helpful answers, so I
was hoping someone here could clear this up.

For example, let's say I had an app that kept a list of books for each
user like this:

class BookList(models.Model):
user = models.ForeignKey(User)
book = models.ForeignKey(Book)

class Book(models.Model):
author = models.ForeignKey(Author)
name = models.CharField(max_length=300)

class Author(models.Model):
name = models.CharField(max_length=300)

I had thought that to generate a bunch of forms for BookList (so that
the current user could for example, enter in all of the books that
they've read on a single page), I would use an inlineformset like so:

BookListFormSet = inlineformset_factory(User, BookList)
booklist_formset = BookListFormSet(instance=currentUser)

However, the resulting formset I get results in a dropdown menu for
each book field in the forms, but I don't want that. I want two
TextInput widgets in the form such that the user can type out:
   Alice in Wonderland
   Lewis Carroll
and if some other user has already added "Alice in Wonderland" to
their book list, then BookList.book will just point to that book.  BUT
if this is the first user to add "Alice in Wonderland" to their book
list, I want the form to create a brand new row in the Book table (and
a brand new row in Author if there is no "Lewis Carroll" books yet
either).

I'm new to Django, so maybe the solution is obvious to many.  But like
I said, I'm finding lots of people asking this question, but without
any good answers posted.

If someone could please provide a detailed solution I would very much
appreciate it, and I imagine others would as well.

Thanks in advance.  If any part of what I'm asking isn't clear, don't
hesitate to ask me about it.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



admin inline formset using incorrect form

2011-04-12 Thread shanyu
Hi, please take a look at the following code.

def create_foo_form(baz):
class FooForm(forms.ModelForm):
   def __init__(self, *args, **kwargs):
   print "Initializing a FooForm object"
   # Init stuff here
return FooForm

class FooInline(admin.TabularInline):
model = Foo

def get_formset(self, request, obj=None, **kwargs):
if obj:
kwargs['form'] = create_foo_form(obj)
return super(FooInline, self).get_formset(request, obj,
**kwargs)

class BazAdmin(admin.ModelAdmin):
inlines = [FooInline,]


Suppose we are changing a Baz object. First, get_formset method will
be passed the Baz object as obj and following that a FooForm class
will be created and passed to the superclass method.

Here's the part that's beyond my understanding: After that,
get_formset gets executed for an extra time with obj=None. Because obj
is None, the method doesn't pass FooForm to the superclass method, and
therefore the superclass is expected to construct the formset using
default form (self.form - which is not FooForm). But to my surprise I
am getting FooForm objects initialized.

So I have 2 questions:
1. Why does get_formset get called an extra time with obj=None?
2. Why are FooForm objects used when a formset is constructed in this
second time?

Regards.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: inline formset validation error

2011-02-13 Thread Shawn Milochik
You can iterate through the forms in your formset and call is_valid()
(and optionally save()) on them based on your needs.

Since your definition of "left blank" and "invalid" could vary based
on what you're doing, it's better that you make those decisions
explicit. If Django tried to decide for you, it would be "magic" at
best and wrong at worst.

Shawn

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



inline formset validation error

2011-02-13 Thread Sarang
I have an inline formset that has max_num=3 and extra=3. The form is 
displayed correctly, however, is_valid() on the formset returns a False with 
error:
[{}, {'tag': [u'This field is required.']}, {'tag': [u'This field is 
required.']}]

The first form has no error as the user has set some value to the field 
"tag". However, the user has not touched the other two forms. 

I thought the extra forms are optional isn't it? If their data is not valid, 
shouldn't Django ignore them and move on? Am I doing something wrong and is 
there a workaround to this problem?

Thanks
Sarang

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Django inline formset gotcha

2010-11-07 Thread h3
Well .. nevermind.

http://haineault.com/blog/142/


On Nov 6, 10:50 pm, h3 <hainea...@gmail.com> wrote:
> I've been banging my head on this problem for many hours and nobody
> came up with a
> working solution ..
>
> I've tried so many things to work around this problem that I've
> decided to write a blog
> listing them to save you all some time:
>
> http://haineault.com/blog/141/
>
> TL;DR: inline formset + post_save signal = cannot access inlines'
> updated data.
>
> Think of an invoice system were the inlines are the invoice's lines
> which you use to
> calculate the invoice's total.
>
> You just can't have that total upon save nor with post_save signal
> under *any* circumstances.
> Unless you hit the save button twice, then the second time the right
> total will show up. Of
> course this is problematic on many levels, but in my case I need to
> send an email with the
> actual data after the save.
>
> Please someone tell me I'm retarded and that there is a simple obvious
> solution hidden in plain
> sigh that escaped me.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Django inline formset gotcha

2010-11-06 Thread h3
I've been banging my head on this problem for many hours and nobody
came up with a
working solution ..

I've tried so many things to work around this problem that I've
decided to write a blog
listing them to save you all some time:

http://haineault.com/blog/141/

TL;DR: inline formset + post_save signal = cannot access inlines'
updated data.

Think of an invoice system were the inlines are the invoice's lines
which you use to
calculate the invoice's total.

You just can't have that total upon save nor with post_save signal
under *any* circumstances.
Unless you hit the save button twice, then the second time the right
total will show up. Of
course this is problematic on many levels, but in my case I need to
send an email with the
actual data after the save.

Please someone tell me I'm retarded and that there is a simple obvious
solution hidden in plain
sigh that escaped me.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Custom Inline Formset Validation

2010-08-12 Thread kkerbel
To clarify, by "checked" I mean there is a booleanfield and I only
want to let the user select 5 of those at a time across the inline
formset.



On Aug 12, 1:14 pm, kkerbel <kker...@gmail.com> wrote:
> I'm trying to do some custom validation for an inlineformset.  I would
> like to only allow 5 items checked across the forms in the inline
> formset.  What's the best way to do this?  I have tried defining a
> method (like a clean method for forms and formsets) but it doesn't
> appear to work.  Maybe I'm defining it the wrong way but I'm mainly
> asking who has done this and, in general, what is the best way to
> validate data in an inline formset.
>
> Thanks!

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Custom Inline Formset Validation

2010-08-12 Thread kkerbel
I'm trying to do some custom validation for an inlineformset.  I would
like to only allow 5 items checked across the forms in the inline
formset.  What's the best way to do this?  I have tried defining a
method (like a clean method for forms and formsets) but it doesn't
appear to work.  Maybe I'm defining it the wrong way but I'm mainly
asking who has done this and, in general, what is the best way to
validate data in an inline formset.

Thanks!

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Inline formset when pk doesn't exist

2010-07-26 Thread cerberos
I've managed to solve my problem.

view

item_form = ItemForm()
ImageFormSet = formset_factory(ImageForm)
image_formset = ImageFormSet()


template (I'm using uni_form in the template but it's no different)

{{ image_formset.management_form }}
{{ item_form|as_uni_form }}

{% for form in image_formset.forms %}
{{ form|as_uni_form }}
{% endfor %}

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Inline formset when pk doesn't exist

2010-07-26 Thread cerberos
I have 2 models

class Item(models.Model):
fields here

class ItemImage(models.Model):
item = models.ForeignKey('Item', null=True, blank=True,
related_name='images')

I want a single 'form' where a user can add an Item and an ItemImage
(actually many images but that's irrelevant at this stage). I want to
use an inline formset but the Item instance doesn't exist so there's
no primary key, I have tried but get an error relating the the lack of
primary key (...django/forms/models.py in _get_foreign_key, line 796).

I'm pretty sure this can't be done with inline formsets so I figure
that I should add an ItemImage formset to the Item form somehow, I
just don't know how (and it doesn't seem to be covered in the docs).

I'd appreciate any help I can get as I've hit a brick wall.

Many thanks


-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Inline formset customization

2010-04-09 Thread pinco
Hi Guys,

I'm try to figure out how add some customized functionalities to an
inline formset. What I would implement are the two following features:
- ability to delete a record by pressing a submit button assigned to
each row (instead of checking the delete box and submitting the
overall form)
- ability to preserve the extra forms number and order after the
submission

To better explain the second point, suppose there are 3 records on the
db and the user adds 3 extra forms (using eg. the technique described
here: 
http://www.falconhat.com/tutorials/django-adding-inline-formset-rows-without-javascript/).
The user then decides to delete the second record.
I would that, after the submission, the form has 2 records and 3
extra, blank forms. Additionally, if the user fills partially one or
more of the additional forms, I would the filled forms to keep the new
content.

Can somebody give me some hints on how to implement these
functionalities?
By the way, while the above functionalities seem to be easy to
implement using JavaScript, I'm keen to avoid to use it.


Many thanks for your invaluable help.


Cheers,

Paolo

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



custom validation for an inline formset, howto?

2010-02-24 Thread dan levine
I am trying to perform custom validation on an inline formset.  The
docs indicate that custom formset validation should go through a
custom clean method:

http://docs.djangoproject.com/en/1.1/topics/forms/formsets/#custom-formset-validation

but the clean method doesn't get called for my instance of an inline
formset when I call is_valid() on the formset.

Conceptually, I have Client model with many PhoneNumber models for my
inline formset, and want to do some validation on the phone number
fields based on fields in client.  The relevant code snippets for my
project:

custom form code:

class BaseClientPhoneInlineFormSet(BaseInlineFormSet):
  # do nothing pass-through method, but see that logging statement
prints
  def __init__(self, data=None, files=None, instance=None,
   save_as_new=False, prefix=None):
logging.debug("IN client.forms.BaseClientPhoneFormset.__init__")
super(BaseClientPhoneInlineFormSet, self).__init__(data, files,
instance, save_as_new, prefix)

  # this should do validation, but doesnt.  this logging statement
never prints
  def clean(self):
logging.debug("IN client.forms.BaseClientPhoneFormset.clean")
super(BaseClientPhoneInlineFormSet, self).clean()
raise forms.ValidationError("Test Inline Formset Clean Fail.")


view code:

  ClientPhoneFormSet = inlineformset_factory(models.Client,
models.PhoneNumber, formset=BaseClientPhoneInlineFormSet)
  formset = ClientPhoneFormSet(request.POST, instance=client_ref)
  formset.is_valid():  # no validation error thrown, returns true


The __init__ logging message is output, but the clean logging message
is not, and no ValidationError is thown on is_valid().

I've searched and not found any similar questions which makes me think
I'm missing something obvious :-/

Thanks for any help.

dan

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Save as inline formset

2010-02-10 Thread Karen Tracey
On Wed, Feb 10, 2010 at 7:45 AM, oiad  wrote:

> Hi. If I have a couple of models like these:
>
> class Poll(models.Model):
>question = models.CharField(max_length=200, unique = True)
>pub_date = models.DateTimeField('date published')
>
> class Choice(models.Model):
>poll = models.ForeignKey(Poll)
>choice = models.CharField(max_length=200)
>votes = models.IntegerField()
>
> and in admin.py I put "save_as=True" and I try to save a poll as a new
> one, but I forget to change the question, since I want that to be
> unique, I get an error as it supposed to be, but if I change the
> question and try to save the poll I get this error:
> invalid literal for int() with base 10: ''


This looks like a bug somewhere along the line of processing that sequence
(save-as that fails due to a validation error for an object with at least
one inline, correct the error, try to save again), though I'm not sure
where.  I don't recall this being reported before so if you could open a
ticket for it that would be good.

Karen

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Save as inline formset

2010-02-10 Thread oiad
Hi. If I have a couple of models like these:

class Poll(models.Model):
question = models.CharField(max_length=200, unique = True)
pub_date = models.DateTimeField('date published')

class Choice(models.Model):
poll = models.ForeignKey(Poll)
choice = models.CharField(max_length=200)
votes = models.IntegerField()

and in admin.py I put "save_as=True" and I try to save a poll as a new
one, but I forget to change the question, since I want that to be
unique, I get an error as it supposed to be, but if I change the
question and try to save the poll I get this error:
invalid literal for int() with base 10: ''
and as I read on the error page I noted this:

choice_set-1-choice  u'3'
_save u'Gravar'
choice_set-0-choice u'2'
choice_set-1-votes u'0'
choice_set-1-id u''
questionu'Idade'
choice_set-0-poll u''
choice_set-INITIAL_FORMS u'3'
choice_set-2-choice u'1'
pub_date_1 u'12:40:48'
pub_date_0 u'2010-02-10'
choice_set-2-votes u'0'
choice_set-2-poll u''
choice_set-0-votes u'0'
choice_set-2-id u''
choice_set-0-id u''
choice_set-1-poll u''
choice_set-TOTAL_FORMS u'6'

The foreign key and the id's are missing.
Did someone else had this error? Is it a django bug? Am I doing
something wrong? I've searched google but I couldn't find anything
that could help me.

Thanks.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



inline formset

2010-01-14 Thread Frédéric Burlet

Hi,

I'm a bit stuck with inline formset. I missed something.
I'm using django 1.1.1.

I have a model:

class Address(models.Model):
street = ...
number = ...
...

class Person(models.Model):
first_name = ...
last_name =
address = models.ForeignKey(Address)
...

Based on this model, I would like to have one form to add a person and her 
address. In order to achieve this, I'm using inline formset.

As far as I understood, formset allows to add multiple form on a page and 
inline formset is an extension that allows to play with related objects.

I written the following view (based on the documentation located at [1])

[1] http://docs.djangoproject.com/en/1.1/topics/forms/modelforms/#inline-
formsets

def add_person_form(request):

address = Address()
PersonFormSet = inlineformset_factory(Address, Person, max_num = 1, 
can_delete = False)

if request.method == 'POST':
formset = PersonFormSet(request.POST, request.FILES, instance = 
address)
if formset.is_valid():
formset.save()
return redirect('/person')
else:
formset = PersonFormSet(instance = address)
return render_to_response('person/add_form.html', { "formset": formset } )


My template looks like (simplified version):


 {{ formset }}


This only displays the person but not the address.

Extra question: if I want to display the fields in a given order, let's say: 
first_name, last_name, and then all fields from Address object followed by the 
remaining fields from Person. What is the best way of doing it ?

Thanks for your support,

Frédéric Burlet.



signature.asc
Description: This is a digitally signed message part.


Re: 'QuerySet' object has no attribute 'ordered' Error When Using Inline Formset

2009-12-08 Thread Karen Tracey
On Tue, Dec 8, 2009 at 11:13 PM, saved...@gmail.com wrote:

> Every time I try to access a formset via inlineformset_factory I get
> the following error messages:
>
> Traceback:
> [snip]
> File "/home/luckybs/webapps/django1/lib/python2.5/django/forms/
> models.py" in get_queryset
>  495. if not qs.ordered:
>
> Exception Type: AttributeError at /questions/10/add_answer/
> Exception Value: 'QuerySet' object has no attribute 'ordered'
>
> I just updated my forms directory on my shared host from 1.0 to 1.2
> (Perhaps that could be the problem?)
>

First, 1.2 does not yet exist.  It's in development.  Perhaps you mean you
updated to a recent SVN checkout?

Second, you updated JUST the Django forms directory from 1.0 to ?  If so, yes, that is the problem. The line having the problem is in
django/forms, it is a line added (I think) during 1.1 development, and it
requires other code changes made elsewhere in the Django code base.  You
cannot simply update subdirectories within django individually. Django is an
integrated package: you need update the whole thing, or not at all.

Karen

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.




'QuerySet' object has no attribute 'ordered' Error When Using Inline Formset

2009-12-08 Thread saved...@gmail.com
Every time I try to access a formset via inlineformset_factory I get
the following error messages:

Traceback:
File "/home/luckybs/webapps/django1/lib/python2.5/django/core/handlers/
base.py" in get_response
  86. response = callback(request, *callback_args,
**callback_kwargs)
File "/home/luckybs/webapps/django1/lib/python2.5/django/contrib/auth/
decorators.py" in __call__
  67. return self.view_func(request, *args, **kwargs)
File "/home/luckybs/webapps/django1/languagen/questions/views.py" in
add_answer
  134. formset =  AnswerFormSet()
File "/home/luckybs/webapps/django1/lib/python2.5/django/forms/
models.py" in __init__
  724. queryset=qs)
File "/home/luckybs/webapps/django1/lib/python2.5/django/forms/
models.py" in __init__
  459. super(BaseModelFormSet, self).__init__(**defaults)
File "/home/luckybs/webapps/django1/lib/python2.5/django/forms/
formsets.py" in __init__
  44. self._construct_forms()
File "/home/luckybs/webapps/django1/lib/python2.5/django/forms/
formsets.py" in _construct_forms
  87. for i in xrange(self.total_form_count()):
File "/home/luckybs/webapps/django1/lib/python2.5/django/forms/
models.py" in total_form_count
  734. return super(BaseInlineFormSet, self).total_form_count
()
File "/home/luckybs/webapps/django1/lib/python2.5/django/forms/
formsets.py" in total_form_count
  68. total_forms = self.initial_form_count() + self.extra
File "/home/luckybs/webapps/django1/lib/python2.5/django/forms/
models.py" in initial_form_count
  729. return super(BaseInlineFormSet, self).initial_form_count
()
File "/home/luckybs/webapps/django1/lib/python2.5/django/forms/
models.py" in initial_form_count
  464. return len(self.get_queryset())
File "/home/luckybs/webapps/django1/lib/python2.5/django/forms/
models.py" in get_queryset
  495. if not qs.ordered:

Exception Type: AttributeError at /questions/10/add_answer/
Exception Value: 'QuerySet' object has no attribute 'ordered'

I just updated my forms directory on my shared host from 1.0 to 1.2
(Perhaps that could be the problem?)
The error message further states that the exact error message resides
i the following:

/home/luckybs/webapps/django1/lib/python2.5/django/forms/models.py in
get_queryset

 488. qs = self.queryset
 489. else:
 490. qs = self.model._default_manager.get_query_set()
 491.
 492. # If the queryset isn't already ordered we need to add an
 493. # artificial ordering here to make sure that all formsets
 494. # constructed from this queryset have the same form order.

 495. if not qs.ordered: ...

 496. qs = qs.order_by(self.model._meta.pk.name)
 497.
 498. if self.max_num > 0:
 499. self._queryset = qs[:self.max_num]
 500. else:
 501. self._queryset = qs

Can anyone point me in the right direction?

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.




filter foreign key field in inline formset

2009-12-07 Thread cerberos
One of the fields in an inline formset has a foreign key to another
model, how can I filter it?

I'm building a library system, the models are loans, loan items and
book instances. I don't want books that are currently out on loan to
be available on the loan items dropdown list.

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.




Inline formset question

2009-10-20 Thread Aizen

I have the following models and I'd like to use them to generate a
contact form...now I know I'm suppossed to use inline formsets, but
I've never been able to make heads or tails of how to make this
work...I want to have the first name, last name, email, phone number,
best time to contact, and the message in my view.  How should I go
about this?

class BestTime(models.Model):
  contact_time = models.CharField(max_length=20)
  start_time = models.TimeField()
  end_time = models.TimeField()
  def __unicode__(self):
return self.contact_time

class Customer(models.Model):
  date_time_added = models.DateTimeField(default=datetime.today)
  first_name = models.CharField(max_length=20)
  last_name = models.CharField(max_length=20)
  email_address = models.CharField(max_length=75)
  phone_number = models.CharField(max_length=20)
  best_time_to_contact = models.ForeignKey(BestTime)
  def __unicode__(self):
 return self.first_name

class MessageType(models.Model):
  type = models.CharField(max_length=20)
  def __unicode__(self):
 return self.type

class Message(models.Model):
  date_time_added = models.DateTimeField(default=datetime.today)
  message_type = models.ForeignKey(MessageType)
  customer = models.ForeignKey(Customer)
  message = models.TextField()
  def __unicode__(self):
return self.date_time_added

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: form and related inline formset on same page

2009-10-01 Thread Daniel Roseman

On Oct 1, 3:09 pm, kurak <kurc...@gmail.com> wrote:
> Hello,
> How can I render new form for object X and inline formset for model Y
> (with foreign key to X) on the same- the same way it's done in django-
> admin.
>
> I've been struggling with it for a while, I tried to render form and
> formset separately but it won't work this way.
>
> How should I approach this?

What doesn't work? What part of the documentation (http://
docs.djangoproject.com/en/dev/topics/forms/modelforms/#using-an-inline-
formset-in-a-view) is not clear? What happens when you try?
--
DR.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



form and related inline formset on same page

2009-10-01 Thread kurak

Hello,
How can I render new form for object X and inline formset for model Y
(with foreign key to X) on the same- the same way it's done in django-
admin.

I've been struggling with it for a while, I tried to render form and
formset separately but it won't work this way.

How should I approach this?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Inline Formset Validation

2009-07-02 Thread KRH

A question on forms; I had asked something similar on StackOverflow
but found the solution didn't really work for me. Let's say I have an
Article class and a Photo class, and I want to be able to attach
Photos to Articles. I create an ArticlePhotoSet class, and make it an
InlineForm in the Article's Admin class. Here's the problem:

Articles can be assigned to a site, and Photos can be assigned to a
site. Each time an Article is saved in the admin, the form needs to
throw an error if any of the Photos pointed to by the ArticlePhotoSet
inlines don't belong to the same site(s) that the Article does. The
problem is that in the ArticlePhotoSet formset, self.instance in the
clean() function refers to what is currently saved for the article,
not what the Article form is 'proposing' the new site be in the form.
So any check placed in the ArticlePhotoSet formset clean() is
referring to what the site value is, not what it will be. Conversely,
the formset doesn't seem to be accessible from the cleaning method of
the Article form itself, so the Article's form can't do the check. Is
there a way to do what I'm trying to accomplish without falling back
onto something more extreme like AJAX checks when the Article's site
value is changed on the form?

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Custom validation for inline formset in Admin

2009-03-11 Thread ljholish

I have a UserProfile related to auth's User model with a couple of
extra date fields, start_date and end_date. I would like one and only
one UserProfile that is editable inline with the parent User model in
my Admin app. This part is working, but I would also like to do custom
validation on the date fields in UserProfile so that start_date <
end_date and also make sure that the lone UserProfile does not have a
delete checkbox in the Admin. Here is a bit of the code:

models.py:

class UserProfile(models.Model):
user = models.ForeignKey(User, unique=True)
start_date = models.DateField()
end_date = models.DateField()

admin.py:

class UserProfileInlineFormSet(BaseInlineFormSet):

def __init__(self, *args, **kwargs):
super(UserProfileInlineFormSet, self).__init__(self, *args,
**kwargs)
self.can_delete = False

# Validate end_date > start_date
def clean(self): # ?
pass

class UserProfileInline(admin.TabularInline):
model = UserProfile
fk_name = 'user'
max_num = 1
formset = UserProfileInlineFormSet

class MyUserAdmin(admin.UserAdmin):
inlines = [UserProfileInline, ]

The docs explain how to do custom validation on a single ModelForm,
but I'm having trouble abstracting that to an inline formset. I
started with trying to define my own formset in the UserProfileInline
class, but I'm not clear on what method to override in order to do the
validation. Any tips or pointers?

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Inline Formset Question

2009-03-10 Thread Ardesco

Hi everyone. I still consider myself to be fairly new to Django, and I
was wondering if the following was possible with inline formsets in
the admin:

I want to create a little questionnaire app in the admin that is pre-
populated with 25 questions in a specific order such that all the user
has to do is click on the response (as opposed to selecting a question
AND an answer). I have little/no experience using formsets, but I was
wondering if this was easily do-able. As a further caveat, I would
really like it if I could pre-populate questions from my database, as
opposed to hardcoding initial values in admin.py. Is this feasible?
Can someone explain/show some code snippets that explains what I want
to do?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Bound Inline Formset doesn't render FileField's current value, needs to be reentered.

2009-01-28 Thread Rodrigo C.

> Just a suggestion -- if the admin site does the sort of thing you want, then
> taking a look at the admin code would probably be helpful in figuring out
> how to do it. Sorry I don't know offhand without doing more digging than I
> have time for what it does, exactly, but if it is showing a working example
> of the kind of thing you want then, since the source is all available, the
> answer is there somewhere.
>
> Karen

Solid advice. Will look into it.

Thanks,

Rodrigo


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Bound Inline Formset doesn't render FileField's current value, needs to be reentered.

2009-01-28 Thread Karen Tracey
On Tue, Jan 27, 2009 at 5:48 PM, Rodrigo C.  wrote:

>
> > This isn't a Django issue. It's a standard property of browsers: you
> > can't set an initial value for file input fields. This is a security
> > measure, to stop malicious pages uploading files from your hard drive
> > without your explicit instruction.
>
> I see. If there's no way to set the initial value for the field, would
> there be some way to make Django not return an error when the user
> tries to save the field without re-uploading the file? And maybe
> display the current value so the user knows it's already uploaded (as
> the admin site does)?
>

Just a suggestion -- if the admin site does the sort of thing you want, then
taking a look at the admin code would probably be helpful in figuring out
how to do it. Sorry I don't know offhand without doing more digging than I
have time for what it does, exactly, but if it is showing a working example
of the kind of thing you want then, since the source is all available, the
answer is there somewhere.

Karen

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Bound Inline Formset doesn't render FileField's current value, needs to be reentered.

2009-01-28 Thread Rodrigo C.

Hi Malcolm, thanks for your reply.

> So, perhaps you could give a small, reduced to the minimum, example of
> how you're setting all this up. Maybe it's a problem in inline formsets,
> or maybe it's an oversight in your code. At the moment, hard to tell.
>

I included the View and Model in my original post, I reproduce it here
in case you don't have access to the whole thread:

Here's the view, the Parent model is "Articulo", the inline model is
"Archivo":

ArchivoInlineFormSet = inlineformset_factory(Articulo, Archivo,
extra=3)
@login_required
def create_article(request, id=False):
text = "Enviar"
button = "Enviar"
user = request.user
if request.method == 'POST':
#save data for new article
form = ArticuloForm(request.POST, request.FILES)
if form.is_valid():
#save info
articulo = form.save()
articulo.autores.add(user.get_profile())
articulo.save()
formset = ArchivoInlineFormSet(request.POST,
request.FILES,  instance=articulo)
if formset.is_valid():
formset.save()
else:
#start editing new article
form = ArticuloForm()
formset = ArchivoInlineFormSet()
objContext = RequestContext(request, locals())
return render_to_response("editar/articulo.html", objContext)

--

And the class, the troublesome field is "archivo":

class Archivo(models.Model):
articulo = models.ForeignKey(Articulo)
tipo = models.IntegerField()
numero = models.IntegerField()
archivo = models.FileField(upload_to="archivos")
etapa = models.IntegerField()

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Bound Inline Formset doesn't render FileField's current value, needs to be reentered.

2009-01-27 Thread Malcolm Tredinnick

On Tue, 2009-01-27 at 14:48 -0800, Rodrigo C. wrote:
> > This isn't a Django issue. It's a standard property of browsers: you
> > can't set an initial value for file input fields. This is a security
> > measure, to stop malicious pages uploading files from your hard drive
> > without your explicit instruction.
> 
> I see. If there's no way to set the initial value for the field, would
> there be some way to make Django not return an error when the user
> tries to save the field without re-uploading the file? And maybe
> display the current value so the user knows it's already uploaded (as
> the admin site does)?

This depends on how you're using the formset. In order not to raise an
error, the form field involved has to know that there is a previous
value and what it is. The standard FileField form field already does
that (if no data is submitted and the "initial" value on the field is
set, it passes validation).

Displaying the initial value for file fields is something that has to be
done manually in form display, from memory.

So, perhaps you could give a small, reduced to the minimum, example of
how you're setting all this up. Maybe it's a problem in inline formsets,
or maybe it's an oversight in your code. At the moment, hard to tell.

Regards,
Malcolm



--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Bound Inline Formset doesn't render FileField's current value, needs to be reentered.

2009-01-27 Thread Rodrigo C.

> This isn't a Django issue. It's a standard property of browsers: you
> can't set an initial value for file input fields. This is a security
> measure, to stop malicious pages uploading files from your hard drive
> without your explicit instruction.

I see. If there's no way to set the initial value for the field, would
there be some way to make Django not return an error when the user
tries to save the field without re-uploading the file? And maybe
display the current value so the user knows it's already uploaded (as
the admin site does)?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Bound Inline Formset doesn't render FileField's current value, needs to be reentered.

2009-01-27 Thread Daniel Roseman

On Jan 27, 9:11 pm, "Rodrigo C." <rodrigo...@gmail.com> wrote:
> I have model that represents a file, and has a FileField, that I am
> rendering via an Inline Formset. When a user fills in the form it gets
> saved with no problems.
> However, I want the users to be able to continue editing the file, but
> when I re-display the newly created object, the data for the FileField
> doesn't show, so if the user edits some data but doesn't re-upload the
> file, she gets an error.
> How can I make the formset render the FileField's current value within
> the form field?
>


This isn't a Django issue. It's a standard property of browsers: you
can't set an initial value for file input fields. This is a security
measure, to stop malicious pages uploading files from your hard drive
without your explicit instruction.

There isn't really any way round it, except to do something extremely
complicated like GMail does and upload the file in the background
while the user fills in the form, then replace the file field with a
reference to the uploaded version of the file.
--
DR.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Bound Inline Formset doesn't render FileField's current value, needs to be reentered.

2009-01-27 Thread Rodrigo C.

I have model that represents a file, and has a FileField, that I am
rendering via an Inline Formset. When a user fills in the form it gets
saved with no problems.
However, I want the users to be able to continue editing the file, but
when I re-display the newly created object, the data for the FileField
doesn't show, so if the user edits some data but doesn't re-upload the
file, she gets an error.
How can I make the formset render the FileField's current value within
the form field?

Here's the view, the Parent model is "Articulo", the inline model is
"Archivo":

ArchivoInlineFormSet = inlineformset_factory(Articulo, Archivo,
extra=3)

@login_required
def create_article(request, id=False):
text = "Enviar"
button = "Enviar"
user = request.user

if request.method == 'POST':
#save data for new article
form = ArticuloForm(request.POST, request.FILES)

if form.is_valid():
#save info
articulo = form.save()
articulo.autores.add(user.get_profile())
articulo.save()

formset = ArchivoInlineFormSet(request.POST,
request.FILES,  instance=articulo)
if formset.is_valid():
formset.save()

else:
#start editing new article
form = ArticuloForm()
formset = ArchivoInlineFormSet()

objContext = RequestContext(request, locals())
return render_to_response("editar/articulo.html", objContext)

and the class, the troublesome field is "archivo":

class Archivo(models.Model):
articulo = models.ForeignKey(Articulo)
tipo = models.IntegerField()
numero = models.IntegerField()
archivo = models.FileField(upload_to="archivos")
etapa = models.IntegerField()
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: disable delete checkbox in Inline formset

2008-09-08 Thread Kurczak



On 8 Wrz, 22:02, David Zhou <[EMAIL PROTECTED]> wrote:
> On Sep 8, 2008, at 2:55 PM, Kurczak wrote:
> > On 8 Wrz, 20:37, David Zhou <[EMAIL PROTECTED]> wrote:
> >> On Sep 8, 2008, at 2:30 PM, Kurczak wrote:
>
> >>> Is there any way to disable/remove the delete checkbox for inline
> >>> formsets ( in admin) ?
> >>> I found nothing about it in docs, and I believe there's no way to  
> >>> pass
> >>> the 'can_delete' parameter to inlineformset_factory. Obviously I can
> >>> disable the "Can delete" permission, but the ugly box is still  
> >>> there.
>
> >> Have you tried editing the admin templates to not show the checkbox?
> > Hi David,
> > thanks for your reply.
> > I just did in fact, but that affects every single inline form in the
> > project, and that's not what I want. There's no way to load inline
> > template (in admin) for selected app from what I learned. And I'd
> > rather not modify anything in django code because i don't really
> > consider that as solution.
> > Is there any other way?
>
> You're not really modifying django, since you can include the templats  
> in your templates folder, and override them.
>
> If you want app specific admin templates, one way is to wrap the admin  
> views -- for example, see:
>
> http://trac.django-cms.org/trac/browser/trunk/cms/admin_views.py
Thank you, I'll look into that.

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: disable delete checkbox in Inline formset

2008-09-08 Thread David Zhou

On Sep 8, 2008, at 2:55 PM, Kurczak wrote:

> On 8 Wrz, 20:37, David Zhou <[EMAIL PROTECTED]> wrote:
>> On Sep 8, 2008, at 2:30 PM, Kurczak wrote:
>>
>>> Is there any way to disable/remove the delete checkbox for inline
>>> formsets ( in admin) ?
>>> I found nothing about it in docs, and I believe there's no way to  
>>> pass
>>> the 'can_delete' parameter to inlineformset_factory. Obviously I can
>>> disable the "Can delete" permission, but the ugly box is still  
>>> there.
>>
>> Have you tried editing the admin templates to not show the checkbox?
> Hi David,
> thanks for your reply.
> I just did in fact, but that affects every single inline form in the
> project, and that's not what I want. There's no way to load inline
> template (in admin) for selected app from what I learned. And I'd
> rather not modify anything in django code because i don't really
> consider that as solution.
> Is there any other way?


You're not really modifying django, since you can include the templats  
in your templates folder, and override them.

If you want app specific admin templates, one way is to wrap the admin  
views -- for example, see:

http://trac.django-cms.org/trac/browser/trunk/cms/admin_views.py

---
David Zhou
[EMAIL PROTECTED]




--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: disable delete checkbox in Inline formset

2008-09-08 Thread Daniel Roseman

On Sep 8, 7:55 pm, Kurczak <[EMAIL PROTECTED]> wrote:
> On 8 Wrz, 20:37, David Zhou <[EMAIL PROTECTED]> wrote:> On Sep 8, 2008, at 
> 2:30 PM, Kurczak wrote:
>
> > > Is there any way to disable/remove the delete checkbox for inline
> > > formsets ( in admin) ?
> > > I found nothing about it in docs, and I believe there's no way to pass
> > > the 'can_delete' parameter to inlineformset_factory. Obviously I can
> > > disable the "Can delete" permission, but the ugly box is still there.
>
> > Have you tried editing the admin templates to not show the checkbox?
>
> Hi David,
> thanks for your reply.
> I just did in fact, but that affects every single inline form in the
> project, and that's not what I want. There's no way to load inline
> template (in admin) for selected app from what I learned. And I'd
> rather not modify anything in django code because i don't really
> consider that as solution.
> Is there any other way?
>

Well, it's not true that you can't change the inline template for a
model - you can easily do so by using the 'template' attribute in the
InlineModelAdmin class, see here:
http://docs.djangoproject.com/en/dev/ref/contrib/admin/#inlinemodeladmin-objects

However a better solution would probably be to define your own custom
formset for the inline model, and set can_delete to false there. For
example:

from django.forms import models
from django.contrib import admin

class MyInline(models.BaseInlineFormset):
def __init__(self, *args, **kwargs):
super(MyInline, self).__init__(*args, **kwargs)
self.can_delete = False

class InlineOptions(admin.StackedInline):
model = InlineModel
formset = MyInline

class MainOptions(admin.ModelAdmin):
model = MainModel
inlines = [InlineOptions]


--
DR
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: disable delete checkbox in Inline formset

2008-09-08 Thread Kurczak



On 8 Wrz, 20:37, David Zhou <[EMAIL PROTECTED]> wrote:
> On Sep 8, 2008, at 2:30 PM, Kurczak wrote:
>
> > Is there any way to disable/remove the delete checkbox for inline
> > formsets ( in admin) ?
> > I found nothing about it in docs, and I believe there's no way to pass
> > the 'can_delete' parameter to inlineformset_factory. Obviously I can
> > disable the "Can delete" permission, but the ugly box is still there.
>
> Have you tried editing the admin templates to not show the checkbox?
Hi David,
thanks for your reply.
I just did in fact, but that affects every single inline form in the
project, and that's not what I want. There's no way to load inline
template (in admin) for selected app from what I learned. And I'd
rather not modify anything in django code because i don't really
consider that as solution.
Is there any other way?



> ---
> David Zhou
> [EMAIL PROTECTED]
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: disable delete checkbox in Inline formset

2008-09-08 Thread David Zhou

On Sep 8, 2008, at 2:30 PM, Kurczak wrote:

> Is there any way to disable/remove the delete checkbox for inline
> formsets ( in admin) ?
> I found nothing about it in docs, and I believe there's no way to pass
> the 'can_delete' parameter to inlineformset_factory. Obviously I can
> disable the "Can delete" permission, but the ugly box is still there.

Have you tried editing the admin templates to not show the checkbox?

---
David Zhou
[EMAIL PROTECTED]




--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



disable delete checkbox in Inline formset

2008-09-08 Thread Kurczak

Hi there,
Is there any way to disable/remove the delete checkbox for inline
formsets ( in admin) ?
I found nothing about it in docs, and I believe there's no way to pass
the 'can_delete' parameter to inlineformset_factory. Obviously I can
disable the "Can delete" permission, but the ugly box is still there.

Can anyone help me out with that matter?
Cheers!



--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---