Re: How to know what went wrong with the .save()
On 7/5/07, RajeshD <[EMAIL PROTECTED]> wrote: > Not sure. What RDBMS are you using? I understand about the need to > retain your DB structure as is but are you allowed to *add* new > constraints to the DB? Django does not support multi-column primary key tables. If you'll be doing insert/update/delete, Django will get confused. If you only need read-only access, you can create a shim view over the table, and set the Model's db_table to use the view. If you need write access, I'm afraid you're on shaky ground with Django. There's been interest expressed in doing this before, but if you want to try adding it, it'll be a fairly involved job. --~--~-~--~~~---~--~~ 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: How to know what went wrong with the .save()
On Jul 5, 8:44 am, AnaReis <[EMAIL PROTECTED]> wrote: > Hi again,>From what I could understand, I would have to recreate the database > so > > that django could create an ID field for me. Unfortunately that isn't > possible because I'm using a legacy database and I can't change it. Right. > In > this database, the primary key is the two fields combined, so their > combination has to be unique. Is there a way for me to do this without > having to change the database? Just changing the models.py file? Not sure. What RDBMS are you using? I understand about the need to retain your DB structure as is but are you allowed to *add* new constraints to the DB? --~--~-~--~~~---~--~~ 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: How to know what went wrong with the .save()
Hi again, >From what I could understand, I would have to recreate the database so that django could create an ID field for me. Unfortunately that isn't possible because I'm using a legacy database and I can't change it. In this database, the primary key is the two fields combined, so their combination has to be unique. Is there a way for me to do this without having to change the database? Just changing the models.py file? Thanks for your help! Ana On Jul 5, 8:26 am, AnaReis <[EMAIL PROTECTED]> wrote: > On Jul 4, 4:35 pm, RajeshD <[EMAIL PROTECTED]> wrote: > > > On Jul 4, 12:14 pm, AnaReis <[EMAIL PROTECTED]> wrote: > > > > Hi again, > > > Thanks for the suggestion, but this still isn't working... the > > > difference between this module and the others that I have already made > > > is that (besides the fact that the others actually work) this one > > > involves a table with two primary keys. If it had just one I bet there > > > would be no problem. > > > And you'd win that bet! I should have noticed the two PKs in your > > model. > > > Here's the thing: Django allows only one PK field per object. You > > should remove the two primary_key=True attributes altogether from your > > model (letting Django create a PK id field for you.) Then, use the > > unique_together clause to make the database enforce that the pair > > (level_name, instrument_name) is always unique. That clause is defined > > in your Meta class like this: > > > unique_together = (('level_name', 'instrument_name'),) # Note that > > this is a nested tuple > > > For added measure you can add a db_index=True to your formerly primary > > key fields to make querying over them faster. > > > Don't forget to wipe out the model entirely from your DB table > > (assuming you are in development mode with despensible test data) and > > then syncdb to recreate everything. > > Hi, > Is it possible to do this unique_together field without changing the > database? It's because I'm using a legacy database and I can't change > it. > To create the models I simply used: django-admin.py inspectdb > > models.py > If Django creates the PK id field for me, do you mean it will chose > from one of the fields I will have in the database or will it create a > new field? > The model I'm using is this one: > [models.py] > class Level(models.Model): > level_name = models.CharField(primary_key=True, maxlength=20) > instrument_name = models.CharField(primary_key=True, maxlength=20) > available = models.TextField() > tablename = models.CharField(blank=True, maxlength=20) > def __str__(self): > (..) > class Meta: > db_table = 'Level' > I'm sorry for all my questions but I'm still learning how to work with > Django and there are several things that I still don'tknowhow to > deal with. :) > And thanks for your help and patience! :) > Ana --~--~-~--~~~---~--~~ 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: How to know what went wrong with the .save()
Hi again, >From what I could understand, I would have to recreate the database so that django could create an ID field for me. Unfortunately that isn't possible because I'm using a legacy database and I can't change it. In this database, the primary key is the two fields combined, so their combination has to be unique. Is there a way for me to do this without having to change the database? Just changing the models.py file? Thanks for your help! Ana On Jul 5, 8:26 am, AnaReis <[EMAIL PROTECTED]> wrote: > On Jul 4, 4:35 pm, RajeshD <[EMAIL PROTECTED]> wrote: > > > On Jul 4, 12:14 pm, AnaReis <[EMAIL PROTECTED]> wrote: > > > > Hi again, > > > Thanks for the suggestion, but this still isn't working... the > > > difference between this module and the others that I have already made > > > is that (besides the fact that the others actually work) this one > > > involves a table with two primary keys. If it had just one I bet there > > > would be no problem. > > > And you'd win that bet! I should have noticed the two PKs in your > > model. > > > Here's the thing: Django allows only one PK field per object. You > > should remove the two primary_key=True attributes altogether from your > > model (letting Django create a PK id field for you.) Then, use the > > unique_together clause to make the database enforce that the pair > > (level_name, instrument_name) is always unique. That clause is defined > > in your Meta class like this: > > > unique_together = (('level_name', 'instrument_name'),) # Note that > > this is a nested tuple > > > For added measure you can add a db_index=True to your formerly primary > > key fields to make querying over them faster. > > > Don't forget to wipe out the model entirely from your DB table > > (assuming you are in development mode with despensible test data) and > > then syncdb to recreate everything. > > Hi, > Is it possible to do this unique_together field without changing the > database? It's because I'm using a legacy database and I can't change > it. > To create the models I simply used: django-admin.py inspectdb > > models.py > If Django creates the PK id field for me, do you mean it will chose > from one of the fields I will have in the database or will it create a > new field? > The model I'm using is this one: > [models.py] > class Level(models.Model): > level_name = models.CharField(primary_key=True, maxlength=20) > instrument_name = models.CharField(primary_key=True, maxlength=20) > available = models.TextField() > tablename = models.CharField(blank=True, maxlength=20) > def __str__(self): > (..) > class Meta: > db_table = 'Level' > I'm sorry for all my questions but I'm still learning how to work with > Django and there are several things that I still don'tknowhow to > deal with. :) > And thanks for your help and patience! :) > Ana --~--~-~--~~~---~--~~ 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: How to know what went wrong with the .save()
On Jul 4, 4:35 pm, RajeshD <[EMAIL PROTECTED]> wrote: > On Jul 4, 12:14 pm, AnaReis <[EMAIL PROTECTED]> wrote: > > > Hi again, > > Thanks for the suggestion, but this still isn't working... the > > difference between this module and the others that I have already made > > is that (besides the fact that the others actually work) this one > > involves a table with two primary keys. If it had just one I bet there > > would be no problem. > > And you'd win that bet! I should have noticed the two PKs in your > model. > > Here's the thing: Django allows only one PK field per object. You > should remove the two primary_key=True attributes altogether from your > model (letting Django create a PK id field for you.) Then, use the > unique_together clause to make the database enforce that the pair > (level_name, instrument_name) is always unique. That clause is defined > in your Meta class like this: > > unique_together = (('level_name', 'instrument_name'),) # Note that > this is a nested tuple > > For added measure you can add a db_index=True to your formerly primary > key fields to make querying over them faster. > > Don't forget to wipe out the model entirely from your DB table > (assuming you are in development mode with despensible test data) and > then syncdb to recreate everything. Hi, Is it possible to do this unique_together field without changing the database? It's because I'm using a legacy database and I can't change it. To create the models I simply used: django-admin.py inspectdb > models.py If Django creates the PK id field for me, do you mean it will chose from one of the fields I will have in the database or will it create a new field? The model I'm using is this one: [models.py] class Level(models.Model): level_name = models.CharField(primary_key=True, maxlength=20) instrument_name = models.CharField(primary_key=True, maxlength=20) available = models.TextField() tablename = models.CharField(blank=True, maxlength=20) def __str__(self): (..) class Meta: db_table = 'Level' I'm sorry for all my questions but I'm still learning how to work with Django and there are several things that I still don't know how to deal with. :) And thanks for your help and patience! :) Ana --~--~-~--~~~---~--~~ 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: How to know what went wrong with the .save()
On Jul 4, 12:14 pm, AnaReis <[EMAIL PROTECTED]> wrote: > Hi again, > Thanks for the suggestion, but this still isn't working... the > difference between this module and the others that I have already made > is that (besides the fact that the others actually work) this one > involves a table with two primary keys. If it had just one I bet there > would be no problem. And you'd win that bet! I should have noticed the two PKs in your model. Here's the thing: Django allows only one PK field per object. You should remove the two primary_key=True attributes altogether from your model (letting Django create a PK id field for you.) Then, use the unique_together clause to make the database enforce that the pair (level_name, instrument_name) is always unique. That clause is defined in your Meta class like this: unique_together = (('level_name', 'instrument_name'),) # Note that this is a nested tuple For added measure you can add a db_index=True to your formerly primary key fields to make querying over them faster. Don't forget to wipe out the model entirely from your DB table (assuming you are in development mode with despensible test data) and then syncdb to recreate everything. --~--~-~--~~~---~--~~ 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: How to know what went wrong with the .save()
Hi again, Thanks for the suggestion, but this still isn't working... the difference between this module and the others that I have already made is that (besides the fact that the others actually work) this one involves a table with two primary keys. If it had just one I bet there would be no problem. I don't know why this doesn't save the object. All the inserted data is saved in the Level object correctly as you can see from the output of the error page (because of the assert False I put in the code): level The model file is: [models.py] class LevelForm(forms.Form): level_Name=RegexField('^level\d[a-b]?$', required=True, max_length=20, initial='level', error_message='Blah') instrument_Name=ChoiceField(required=False, choices=[(i.instrument_name,i.instrument_name) for i in Instrument.objects.all()]) available=ChoiceField(required=False, choices=[('Y','Yes'), ('N','No')], initial='Y') table_Name=RegexField('^[a-zA-Z]+$', required=False, max_length=20, error_message='Blah') class Level(models.Model): level_name = models.CharField(primary_key=True, maxlength=20) instrument_name = models.CharField(primary_key=True, maxlength=20) available = models.TextField() tablename = models.CharField(blank=True, maxlength=20) def __str__(self): stringue='level_name - '+self.level_name+' instrument_name - '+self.instrument_name+' available - '+str(self.available)+' tablename - ' if self.tablename== None: stringue=stringue+str(self.tablename) else: stringue=stringue+self.tablename return stringue class Meta: db_table = 'Level' I really don't know how to make this work and I need to make this work :( Ana On Jul 3, 7:55 pm, RajeshD <[EMAIL PROTECTED]> wrote: > Hi Ana, > > > > > [views.py] > > level=Level() > > level.level_name=form.clean_data.get('level_Name') > > level.instrument_name=form.clean_data.get('instrument_Name') > > level.available=form.clean_data.get('available') > > level.tablename=form.clean_data.get('tabelname') > > > level.save() > > > #when I do this instruction to test if anything was inserted > > num=Level.objects.filter(Q(level_name__exact=level.level_name) & > > Q(instrument_name__exact=level.instrument_name)).count() #returns 0L > > Try that without the Q object like this: > > num=Level.objects.filter(level_name__exact=level.level_name, > instrument_name__exact=level.instrument_name).count() > > -Rajesh --~--~-~--~~~---~--~~ 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: How to know what went wrong with the .save()
Hi Ana, > > [views.py] > level=Level() > level.level_name=form.clean_data.get('level_Name') > level.instrument_name=form.clean_data.get('instrument_Name') > level.available=form.clean_data.get('available') > level.tablename=form.clean_data.get('tabelname') > > level.save() > > #when I do this instruction to test if anything was inserted > num=Level.objects.filter(Q(level_name__exact=level.level_name) & > Q(instrument_name__exact=level.instrument_name)).count() #returns 0L Try that without the Q object like this: num=Level.objects.filter(level_name__exact=level.level_name, instrument_name__exact=level.instrument_name).count() -Rajesh --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
How to know what went wrong with the .save()
Hi! In my project, I'm doing a .save() but nothing is being saved and I cant figure out why... The code is: [models.py] class LevelForm(forms.Form): level_Name=RegexField('^level\d[a-b]?$', required=True, max_length=20, initial='level', error_message='Blah') instrument_Name=ChoiceField(required=False, choices=[(i.instrument_name,i.instrument_name) for i in Instrument.objects.all()]) available=ChoiceField(required=False, choices=[('Y','Yes'), ('N','No')], initial='Y') table_Name=RegexField('^[a-zA-Z]+$', required=False, max_length=20, error_message='Blah') class Level(models.Model): level_name = models.CharField(primary_key=True, maxlength=20) instrument_name = models.CharField(primary_key=True, maxlength=20) available = models.TextField() tablename = models.CharField(blank=True, maxlength=20) def __str__(self): stringue='level_name - '+self.level_name+' instrument_name - '+self.instrument_name+' available - '+str(self.available)+' tablename - ' if self.tablename== None: stringue=stringue+str(self.tablename) else: stringue=stringue+self.tablename return stringue class Meta: db_table = 'Level' [views.py] level=Level() level.level_name=form.clean_data.get('level_Name') level.instrument_name=form.clean_data.get('instrument_Name') level.available=form.clean_data.get('available') level.tablename=form.clean_data.get('tabelname') level.save() #when I do this instruction to test if anything was inserted num=Level.objects.filter(Q(level_name__exact=level.level_name) & Q(instrument_name__exact=level.instrument_name)).count() #returns 0L lvl=Level.objects.filter(Q(level_name__exact=level.level_name) & Q(instrument_name__exact=level.instrument_name)) #returns [] (empty list) I have tested with the assert False thingy and everything that I insert in the forms is in the level variable: level So I don't understand why nothing happens... I can't insert a register into the database. I also can't figure out what is going wrong during the save since it returns nothing.. Has anyone got any clue why this is happening? I have done 2 other modules and they work fine, only this one I'm not being able to get working. Thanks! Ana --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---