Re: Changemanipulator and follow true
Ok...I've gotten this working a different way, in case anyone is interested, I thought I'd post it here (although parent_company is currently not saving for some reason..anyone?) Here is my model code...again..notice that the Company has a related Address. class Address(models.Model): address_id = models.AutoField(primary_key=True) street_number = models.IntegerField(null=True, blank=True) street_name = models.CharField(blank=True, maxlength=135) street_suffix = models.TextField(blank=True) city = models.CharField(blank=True, maxlength=135) county = models.CharField(blank=True, maxlength=135) state = models.CharField(blank=True, maxlength=60) country = models.CharField(blank=True, maxlength=135) zip = models.CharField(blank=True, maxlength=30) update_user = models.ForeignKey(UserInfo) #models.IntegerField(null=True, blank=True) time_stamp = models.DateTimeField() class Meta: db_table = 'address' class Company(models.Model): company_id = models.AutoField(primary_key=True) parent_company = models.ForeignKey("self",unique=True,null=True) address = models.ForeignKey(Address,unique=True company_name = models.CharField(blank=True, maxlength=150) company_description = models.CharField(blank=True, maxlength=300) update_user = models.ForeignKey(UserInfo)#models.IntegerField(null=True, blank=True) time_stamp = models.DateTimeField() def __str__(self): return self.company_name class Meta: db_table = 'company' Ok..now my view code..I've subclassed changemanipulator class CustomCompanyChangeManipulator(Company.ChangeManipulator): def __init__(self,company_id): all_companies = Company.objects.all() Company.ChangeManipulator.__init__(self,company_id) self.original_object = Company.objects.get(company_id=company_id) allcomp = () if all_companies: allcomp = [(obj.company_id, obj.company_name) for obj in all_companies] noneobj = ('','') allcomp.insert(0,noneobj) self.fields = ( forms.SelectField(field_name="parent_company_id", is_required=False,choices=allcomp), forms.TextField(field_name="company_name", length=20, is_required=True), forms.TextField(field_name="company_description", maxlength=255, length=30,is_required=True), forms.SelectField(field_name="street_prefix", is_required=False,choices=STREET_PREFIX), forms.IntegerField(field_name="street_number"), forms.TextField(field_name="street_name", length=30, maxlength=45), forms.SelectField(field_name="street_type", is_required=False,choices=STREET_TYPE), forms.TextField(field_name="city", length=30, maxlength=45), forms.SelectField(field_name="state", is_required=True,choices=STATES), forms.TextField(field_name="zip",is_required=True), forms.CheckboxField(field_name="createoffice", is_required=False), ) def flatten_data(self): origcompany = self.original_object fields = dict([(field.name, getattr(origcompany, field.attname)) for field in self.original_object._meta.fields]) for field in origcompany.address._meta.fields: fields[field.name] = getattr(origcompany.address, field.attname) return fields def save(self, new_data): origcompany = self.original_object origcompany.company_name = new_data['company_name'] origcompany.company_description = new_data['company_description'] origcompany.parent_company = new_data['parent_company_id'] origcompany.save() origaddress = origcompany.address origaddress.street_prefix = new_data['street_prefix'] origaddress.street_number = new_data['street_number'] origaddress.street_name = new_data['street_name'] origaddress.street_type = new_data['street_type'] origaddress.city = new_data['city'] origaddress.state = new_data['state'] origaddress.zip = new_data['zip'] Here is where I actually call the code to render the form... def rendereditcompany(request,company_id): current_user = request.session.get('CurrentUser') if not current_user: return HttpResponseRedirect('/rsswww/login') nonfields = {'time_stamp': False,'address':True } manipulator = CustomCompanyChangeManipulator(company_id) company = manipulator.original_object if request.POST: # If data was POSTed, we're trying to create a new Place. new_data = request.POST.copy() # Check for errors. errors = manipulator.get_validation_errors(new_data) if not errors: manipulator.do_html2python(new_data) manipulator.save(new_data) return HttpResponseRedirect('/rsswww/companyadmin') else: print "errors" print manipulator.get_validation_errors(new_data)
Re: Changemanipulator and follow true
[EMAIL PROTECTED] wrote: > I have to keep the Address on Company... as Address will be being used > in other places as well..and is not always related to a company... I > have a Property and User classes as well..and each of them will have an > Address foreign key. Well, I think we'll have to wait the answer of some experienced django user. > In my form I'm using the following ( I tried putting a 0 in there like your > sample..but it gave an unindexable object error ) In that sample I moved the foreign key on the other model. > Now in my company definition I have: > class Company(models.Model): >company_id = models.AutoField(primary_key=True) >parent_company = models.ForeignKey("self",null=True,blank=True) >address =models.ForeignKey(Address,unique=True,edit_inline=models.TABULAR) You've got a one-to-one relation (unique=True). I suppose that using the Address ChangeManipulator could do the trick. > I can't use the address...because an address will be on a company object.. > as well as some others I have..not just only on a Company object. You can use Address ChangeManipulator and hide fields from other models with the follow argument. > but maybe I just can't do this the way I'm wanting... There's always a way ! Remember you can always code all by hand (like a lot of web-developer usually do). At the very beginning I was writing a lot of code to make the things exactly like I wanted, but as time passed, I discovered that django could do the same thing with less effort (and code). And then... zac... dozens of lines of my code gone ! It's a great pleasure. :-) Massimiliano --~--~-~--~~~---~--~~ 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: Changemanipulator and follow true
Hi Massimiliano, I hope you don't mind my emailing you directly... I sent a reply on the groups... but thought I'd send it directly to you as well... since you seem to be using this technique... In my form I'm using the following ( I tried putting a 0 in there like your sample..but it gave an unindexable object error ) Street #:{{ form.address.street_number }} Now in my company definition I have: class Company(models.Model): company_id = models.AutoField(primary_key=True) parent_company = models.ForeignKey("self",null=True,blank=True) address =models.ForeignKey(Address,unique=True,edit_inline=models.TABULAR) #models.IntegerField(null=True, blank=True) company_name = models.CharField(blank=True, maxlength=150) company_description = models.CharField(blank=True, maxlength=300) update_user =models.ForeignKey(UserInfo)#models.IntegerField(null=True, blank=True) time_stamp = models.DateTimeField() def __str__(self): return self.company_name class Meta: db_table = 'company' It isn't erroring out..so it seems to know what the address field is... but doesn't show an edit box? Did I miss something that I should be doing..or can I not do it with the comany change manipulator? I can't use the address...because an address will be on a company object..as well as some others I have..not just only on a Company object. Thanks for any info, Carole On 12/13/06, Massimiliano Ravelli <[EMAIL PROTECTED]> wrote: > > > [EMAIL PROTECTED] ha scritto: > > > I'm not using the admin interface though...will this work with that? > > (I'll give it a shot and see) > > edit_inline argument works well with both admin interface and custom > views (I'm using the latter). > > Massimiliano > > > > > --~--~-~--~~~---~--~~ 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: Changemanipulator and follow true
Ok..this is what I've changed it to... but it's still not displaying an edit box for my street numberI'm using the Company changemanipulator... In my form I'm using the following ( I tried putting a 0 in there like your sample..but it gave an unindexable object error ) Street #:{{ form.address.street_number }} Now in my company definition I have: class Company(models.Model): company_id = models.AutoField(primary_key=True) parent_company = models.ForeignKey("self",null=True,blank=True) address = models.ForeignKey(Address,unique=True,edit_inline=models.TABULAR) #models.IntegerField(null=True, blank=True) company_name = models.CharField(blank=True, maxlength=150) company_description = models.CharField(blank=True, maxlength=300) update_user = models.ForeignKey(UserInfo)#models.IntegerField(null=True, blank=True) time_stamp = models.DateTimeField() def __str__(self): return self.company_name class Meta: db_table = 'company' --~--~-~--~~~---~--~~ 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: Changemanipulator and follow true
[EMAIL PROTECTED] ha scritto: > I'm not using the admin interface though...will this work with that? > (I'll give it a shot and see) edit_inline argument works well with both admin interface and custom views (I'm using the latter). Massimiliano --~--~-~--~~~---~--~~ 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: Changemanipulator and follow true
Hmm... I have to keep the Address on Company... as Address will be being used in other places as well..and is not always related to a company... I have a Property and User classes as well..and each of them will have an Address foreign key. I'd like to be able to show a form for Property and User editing as well..that also shows the address... So would it be form.Company.0.street_number if I wanted to access the address via the Company change manipulator? I am thinking that is not right... but maybe I just can't do this the way I'm wanting... --~--~-~--~~~---~--~~ 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: Changemanipulator and follow true
I'm not using the admin interface though...will this work with that? (I'll give it a shot and see) --~--~-~--~~~---~--~~ 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: Changemanipulator and follow true
I hope I understood your problem (as my english is ugly). I have a similar application: note that I put the foreign key on Address. class Address(models.Model): address_id = models.AutoField(primary_key=True) # Here's the foreign key (note the edit_inline) company = models.ForeignKey(Company, edit_inline=models.TABULAR) status_id = models.IntegerField(null=True, blank=True) ... class Company(models.Model): company_id = models.AutoField(primary_key=True) parent_company = models.ForeignKey("self",null=True,blank=True) ### address = models.ForeignKey(Address) company_name = models.CharField(blank=True, maxlength=150) ... I had no problem with ChangeManipulator (and with a custom manipulator too). Moreover you don't need to specify the follow argument. If you want to keep the foreign key on Company I suppose you must use the Address ChangeManipulator and specify the edit_inline argument. In the template you have to add a 0 (zero) to identify the first address. If you want only one Address per Company you can make the relation one to one adding unique=True to the company field. Street #:{{ form.address.0.street_number }} If you want more documentation, search edit_inline here http://www.djangoproject.com/documentation/model_api/#relationships Hope this helps you. Massimiliano --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Changemanipulator and follow true
I was hoping someone could tell me if there is a way to do this... I thought using follow and true...it should work..but have been unsuccessful. I have an address object that is tied to a company object: class Address(models.Model): address_id = models.AutoField(primary_key=True) status_id = models.IntegerField(null=True, blank=True) street_number = models.IntegerField(null=True, blank=True) street_name = models.CharField(blank=True, maxlength=135) street_suffix = models.TextField(blank=True) unit_number = models.CharField(blank=True, maxlength=30) city = models.CharField(blank=True, maxlength=135) county = models.CharField(blank=True, maxlength=135) state = models.CharField(blank=True, maxlength=60) country = models.CharField(blank=True, maxlength=135) zip = models.CharField(blank=True, maxlength=30) full_address = models.CharField(blank=True, maxlength=765) street_prefix = models.TextField(blank=True) street_type = models.CharField(blank=True, maxlength=30) update_user = models.ForeignKey(UserInfo) #models.IntegerField(null=True, blank=True) time_stamp = models.DateTimeField() class Meta: db_table = 'address' class Company(models.Model): company_id = models.AutoField(primary_key=True) parent_company = models.ForeignKey("self",null=True,blank=True) address = models.ForeignKey(Address) #models.IntegerField(null=True, blank=True) company_name = models.CharField(blank=True, maxlength=150) company_description = models.CharField(blank=True, maxlength=300) update_user = models.ForeignKey(UserInfo)#models.IntegerField(null=True, blank=True) time_stamp = models.DateTimeField() def __str__(self): return self.company_name class Meta: db_table = 'company' I'm trying to make it so that the Company changemanipulator will display the Address fields as well so that both can be edited at the same time. I read something like this in another post on here...but wasn't sure if it should work or not... below is a snippet of my code: nonfields = {'time_stamp': False,'address':True } manipulator = Company.ChangeManipulator(company_id,follow=nonfields) Then in my form..I tried Street #:{{ form.address.street_number }} But that doesn't seem to work... is this not valid... and how should I be doing it? Thanks for any info. Carole --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---