Break statement in Djnago template
Hi group, Is there any break statement in Django template like one in java to break for loop as an element if found . {% for enqhasparent in enqhasparentobjs %} {% ifequal enobj.id enqhasparent.enquiry.id %} {{enobj.student_name|capfirst}} {% endifequal %} {% endfor %} Thanks Ganesh -- 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.
Problem with Image field saving
Hi group , I am getting error like "Key 'fathers_photo' not found in {{fatherprofileform.as_p}} Here FatherProfileForm does not represent UserProfile model .In this case how can the error be rectified ? Ganesh -- 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.
How to lookup tables which has ForeignKey relationship
hi group, class Parent(models.Model): user = models.ForeignKey(User,unique=True) school=models.ForeignKey(School) def __unicode__(self): return self.user.username class Student(models.Model): user = models.ForeignKey(User,unique=True) school=models.ForeignKey(School) standard=models.ForeignKey(Standard) class StudentParent(models.Model): student=models.ForeignKey(Student) parent = models.ForeignKey(Parent) In template,with help of student object I tried to retrieve parent name like {{studentobj.studentparent__parent}} but this could not fetch me the result .please correct me. A simpler way could be to place the parent foreignkey in student table ,but for learning point of view i need to know why do I couldn't hook parent name with the above Thanks ganesh -- 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=.
problem with Imageloading
My requirement is ,user uploaded image has to be saved in Database after a custom validation for size and has to display to user. In models.py class Marketplace(models.Model): title_name=models.CharField(max_length=125) photo1 = models.ImageField(upload_to= 'img/marketplace/%Y/%m/ %d', null=True, blank=True) photo2 = models.ImageField(upload_to = 'img/marketplace/%Y/%m/ %d', null=True, blank=True) In forms.py class MarketplaceForm(forms.Form): title_name = forms.CharField(max_length=125) photo1 = forms.ImageField(required=False) photo2 = forms.ImageField(required=False) def clean_photo1(self): from django.core.files.images import get_image_dimensions logo = self.cleaned_data['photo1'] w, h = get_image_dimensions(logo) if w > 150 or h > 150: raise forms.ValidationError(u'That logo is too big. Please resize it so that it is 32x32 pixels or less, although 150x150 pixels is optimal for display purposes.') return self.cleaned_data['photo1'] def save(self): new_market = Marketplace.objects.create (title_name=self.cleaned_data['title_name'], photo1=self.cleaned_data['photo1'], photo2=self.cleaned_data['photo2'], return new_market In views.py def postyour_adds(request): if request.method=='POST': form=MarketplaceForm(request.POST) if form.is_valid(): newmarket=form.save() return HttpResponseRedirect("/ thanksfor_post/") else: form = MarketplaceForm() return render_to_response("marketplace/ postyour_add.html", {'form': form}) In postyour_add.html {% block content %} Enter your choice {{ form.as_p }} {% endblock %} The Error i am getting says photo1 and photo2 are None Exception Type: TypeError Exception Value: coercing to Unicode: need string or buffer, NoneType found Local vars shows no values is assigned to photo1 and photo2 Any solution please Gjango --~--~-~--~~~---~--~~ 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 to get the value of ForeignKey
thanks for your reply but i cannot solve my problem i will make my question clear this time class BankerCategory(models.Model): name = models.CharField(max_length=125,unique=True) created_on = models.DateTimeField(auto_now_add=True) class Banker(models.Model): name = models.CharField(max_length=125,unique=True) company_name = models.CharField(max_length=125,unique=True) bankercategory = models.ForeignKey(BankerCategory) class Homeloan(models.Model): LOAN_TYPE_CHOICES = ( ('X', 'Fixed'), ('O','FLOATING'), ) banker = models.ForeignKey(Banker) loan_type = models.CharField(max_length=1, choices=LOAN_TYPE_CHOICES) loan_desc = models.TextField() five_year_period_roi = models.FloatField() five_year_period_emi = models.IntegerField() isprivate = models.BooleanField() ispublic = models.BooleanField() First i need to filter Homeloan based on 'loan_type' i.e. fixed or floating then i need to display all the fields of Homeloan based on BankerCategory 'name' Suppose I have BankerCategory name fields as 1.Bank 2.Finance I need to display loan_type:Fixed Bank ... .. Finace ... ... loan_type:Floating Bank ... .. Finace ... ... On Mar 9, 4:00 pm, Malcolm Tredinnick <malc...@pointy-stick.com> wrote: > On Mon, 2009-03-09 at 03:54 -0700, guptha wrote: > > hi gp, > > In models.py > > > class BankerCategory(models.Model): > > name = models.CharField(max_length=125,unique=True) > > > class Banker(models.Model): > > bankercategory = models.ForeignKey(BankerCategory) > > > class Homeloan(models.Model): > > banker = models.ForeignKey(Banker) > > > I need to retrieve 'name' field of 'BankerCategory' with 'Homeloan' > > object > > home=Homeloan.objects.all() > > from this 'home' object how can i access value of 'name' field of > > 'BankerCategory' > > Each Homeloan intsance has a "banker" attribute. You just access it to > refer to the related object. > Seehttp://docs.djangoproject.com/en/dev/topics/db/queries/#related-objects > for all the details. > > 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 -~--~~~~--~~--~--~---
How to get the value of ForeignKey
hi gp, In models.py class BankerCategory(models.Model): name = models.CharField(max_length=125,unique=True) class Banker(models.Model): bankercategory = models.ForeignKey(BankerCategory) class Homeloan(models.Model): banker = models.ForeignKey(Banker) I need to retrieve 'name' field of 'BankerCategory' with 'Homeloan' object home=Homeloan.objects.all() from this 'home' object how can i access value of 'name' field of 'BankerCategory' 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-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 to use post_save signals
hi, thanks a lot for your clarification i have tried it in models.py ,overriding parent save method and everything works fine On Feb 17, 11:56 am, Malcolm Tredinnickwrote: > On Mon, 2009-02-16 at 22:38 -0800, gganesh wrote: > > hi, > > i wrote > > def after_save(sender,instance,created,**kaw): > > instance.acct_number ='RBSB' + str(instance.id) > > instance.save() > > >post_save.connect(after_save,sender=Selector) > > > once when i save it gives out error like > > "maximum recursion depth exceeded in cmp "Exception > > That's not surprising. When you see that error, it's usually a hint that > you've got an infinite loop (the other possibility is that you're doing > a really complex computation, but that's relatively rare, particularly > in web programming), so start looking for what it can be. In this case, > > (1) Something calls Selector.save() > (2) save() finished andpost_savesignal handler is called. > (3) your signal handler calls Selector.save() again > (4) save() calls thepost_savesignal handler (again) > (5) Go back to step 3, repeat forever. > > You're going to have to build something into your signal handler to > detect the loop. One idea might be to add an attribute indicating that > you are already updating it: > > def after_save(sender,instance,created,**kaw): > if hasattr(instance, '_already_saving): > del instance._already_saving > return > instance._already_saving = True > instance.acct_number ='RBSB' + str(instance.id) > instance.save() > > However, in this particular case, it seems like using apost_savesignal > handler might be overkill. Can you override the Selector.save() method > instead? > > Signals are useful, generally, when you want to do something to multiple > models. In this case, the behaviour seems very specific to one > particular model, so just doing it in the model's save method seems more > sensible. > > The one exception to this guideline is if you don't "own" the Selector > source -- if it's a third-party model -- and so can't modify the save() > method. In that case, apost_savehandler can be a way to add new > behaviour. But that's more of a last resort situation. > > 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 -~--~~~~--~~--~--~---
how to make a field uneditable in admin site
hi , i need to know how to create a non editable field in admin site .I tried , one like below acct_number=models.CharField(max_lenght=100,editable=False) but it doesn't work please any other ideas, --~--~-~--~~~---~--~~ 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 to use post_save signals
hi , In models.py i have class Customer(...) bill_no=models.CharFeild(...) All i need to access the field 'bill_no' and assign a value, In views.py i wrote from django.db.models.signals import post_save from mypro.myapp import Customer def after_save(sender,instance,created,**kaw): sender.bill_no='INV'+ str(sender.id) post_save.connect(after_save,sender=Customer) i'm getting an exception as attribute bill_no and id is not found ,so i checked the db tables ,they are present, I suppose i misunderstood the concept .Please help me to find the fault --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---