Re: Is it possible to change the width of the boxes displayed by the filter_horizontal in Django admin interface?
Walt, Thanks for the clarification. That helped a lot. I did get this working. Yeah! Had to do a slight tweak to the surrounding elements on the page to get it to look right (minor change to widgets.css). Now I can see all of the data for the profiles. Seems like there should be a way to auto scale the width based on data, but that's for another time. Thanks for your help. Reed On Mar 26, 10:43 am, Waltwrote: > I'm sorry I wasn't more clear, the class Media just gets > added to your existing admin class. The path to the css > should be the path that is appended to your SETTINGS.PY > media path to reach the css file. The class ResizeFilterAdmin > was just an example name. > > In other words, if your media path is: /var/www/media > and your css file is stored in /var/www/media/css/bisite.css > then your Media entry would be: > > css = { 'all': ('/media/css/bisite.css',)} > > So the full entry would be: > > class ProfileAdmin(admin.ModelAdmin): > search_fields = ('profile_name',) > ordering = ('profile_name',) > filter_horizontal= ('profile_test',) > > class Media: > css = { > 'all':('/media/css/bisite.css',) > } > > Does that make more sense? Again, I apologize for the > miscommunication! > > Thanks, > Walt > > -~ -- 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: Is it possible to change the width of the boxes displayed by the filter_horizontal in Django admin interface?
Walt, Thanks for the response. This is making me crazy. Seems like this should be an easy thing to do. I have tried your suggestion, but I am not totally clear on where in the admin.py It is just not loading up the new media class. Am I supposed to add the resize class as a separate class like this: # class ResizeFilterAdmin(admin.ModelAdmin): class Media: css = { 'all':('bisite.css',) } class ProfileAdmin(admin.ModelAdmin): search_fields = ('profile_name',) ordering = ('profile_name',) filter_horizontal = ('profile_test',) #... or add it into the admin that uses the filter_horizontal like this: class ProfileAdmin(admin.ModelAdmin): search_fields = ('profile_name',) ordering = ('profile_name',) filter_horizontal = ('profile_test',) class ResizeFilterAdmin(admin.ModelAdmin): class Media: css = { 'all':('bisite.css',) } Also, the relative path to the css file? What is that relative to? My admin media so it goes in the same directory as the other admin css files, or relative to my application directory. I appologize for the basic questions. I am just having a hard time grasping the admin modification stuff. On Mar 23, 9:22 am, Waltwrote: > You'll need add a stylesheet Media class to your admin class: > > class ResizeFilterAdmin(admin.ModelAdmin): > # > > class Media: > css = { 'all': ('/relative/path/to/supplemental.css'), } > > Then, in that CSS file you'll need to specify the width of your > element: > > /* by class */ > .filtered { > width: 350px; > > } > > /* or by object id */ > #id_yourfieldname_from { > width: 350px; > > } > > #id_yourfieldname_to { > width: 350px; > > } > > This should work. :-) > > Walt -- 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.
Is it possible to change the width of the boxes displayed by the filter_horizontal in Django admin interface?
I am using the filter_horizontal in my Django admin interface and it works great. Only problem is that some of the data that is contained in the manytomany relationship is longer than the filter_horizontal forms in the admin interface. How do I change the _width_ of the forms displayed. >From looking at the page source it is using a class called _filtered_. From what I can tell that is generated from the contrib/ admin/media/js/SelectFilter2.js, but I don't really understand where the size is set. I was also able to modify the div elements that surround the actual filter_horizontal data by editing the widgets.css, but could not find where the actual _size_ of the filter_horizontal element is controlled. I guessing that I am making this to hard. Does anyone know how to do this? I was hoping it was as easy as adding some meta tags to the actual filter_horizontal line in my admin.py file, but could not find much information on filter_horizontal other than how to use it. Any help is greatly appreciated. rc -- 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.
Increase width of filter_horizontal in django admin
I need to increase the width of the filter_horizontal in my django admin page. When the profile_test (keys off of testcase.test_name which is very wide) fields are displayed both sides of the filter_horizontal are to narrow. How do I increase the width? I don't need the max_length of 300, but 75 would be good. I have a models like this: class Testcase(models.Model): test_id = models.AutoField(primary_key=True) test_name = models.CharField(max_length=300) src = models.ForeignKey(Source, null=True, blank=True, \ help_text='Video source file') asrc = models.ForeignKey(Source, null=True, blank=True, \ help_text='Audio source file') bitrate = models.IntegerField(null=True, blank=True) audio_bitrate = models.IntegerField(null=True, blank=True) test_type = models.CharField(max_length=300) output_resolution = models.CharField(max_length=15, blank=True) out_progressive = models.BooleanField() out_framerate = models.CharField(max_length=10, blank=True) multicodec = models.BooleanField() out_audio_channels = models.CharField(max_length=10, blank=True) out_samplerate = models.IntegerField(null=True, blank=True) out_format = models.CharField(max_length=10, blank=True) out_chan_map = models.CharField(max_length=10, blank=True) description = models.CharField(max_length=3000, blank=True) ref_file = models.CharField(max_length=765, blank=True) ref_encode_filesize = models.IntegerField(null=True, blank=True) ref_y_psnr = models.DecimalField(null=True, max_digits=7, decimal_places=2, blank=True) ref_u_psnr = models.DecimalField(null=True, max_digits=7, decimal_places=2, blank=True) ref_v_psnr = models.DecimalField(null=True, max_digits=7, decimal_places=2, blank=True) ref_yuv_psnr = models.DecimalField(null=True, max_digits=7, decimal_places=2, blank=True) highmark_version = models.CharField(max_length=60, blank=True) def __unicode__(self): return force_unicode(self.test_name) class Meta: ordering = ['test_name'] db_table = u'testcase' class Profile(models.Model): profile_id = models.AutoField(primary_key=True) profile_name = models.CharField(max_length=75) description = models.CharField(max_length=1500, blank=True) profile_test = models.ManyToManyField(Testcase) def __unicode__(self): return force_unicode(self.profile_name) class Meta: ordering = ['profile_name'] db_table = u'profile And model admins like this: class ProfileAdmin(admin.ModelAdmin): search_fields = ('profile_name',) ordering = ('profile_name',) filter_horizontal = ('profile_test') *this is the field i need to be wider** -- 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: Unable to delete certain admin objects. Get "coercing to unicode" error on some, but not all objects.
Ahh. There was one foreign key relationship (table not managed under admin) that i missed. It was indeed returning an int. Fixed it by using force_unicode and it's now working. Thanks Karen. On Jan 6, 7:06 pm, Karen Tracey <kmtra...@gmail.com> wrote: > On Wed, Jan 6, 2010 at 5:20 PM, rc <reedcr...@gmail.com> wrote: > > I get the following error when I try and delete a "testcase": > > > Request Method: GET > > Request URL:http://hades/admin/bisite/testcase/20/delete/ > > Django Version: 1.0.2 final > > Python Version: 2.5.2 > > Installed Applications: > > [snip] > > 679. get_deleted_objects(deleted_objects, perms_needed, > > > request.user, obj, opts, 1, self.admin_site) > > File "/usr/lib/python2.5/site-packages/django/contrib/admin/util.py" > > in get_deleted_objects > > 107. nh(deleted_objects, current_depth, [u'%s: > > %s' % (force_unicode(capfirst(related.opts.verbose_name)), sub_obj), > > []]) > > > Exception Type: TypeError at /admin/bisite/testcase/20/delete/ > > Exception Value: coercing to Unicode: need string or buffer, int found > > > but deleting a "job" works just fine. > > > You can see from my testcase model that it does in fact return a > > string (test_name) > > Admin here is collecting a list of related objects that are going to need to > be deleted as a result of deleting the one you have chosen. So not only > does Testcase need to have a proper unicode-returning __unicode__ > implementation, so does any model that has a ForeignKey pointing to it. > Really, all your __unicode__ methods need to return unicode, not bytestrings > or ints or other objects. > > 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.
Unable to delete certain admin objects. Get "coercing to unicode" error on some, but not all objects.
I get the following error when I try and delete a "testcase": Request Method: GET Request URL: http://hades/admin/bisite/testcase/20/delete/ Django Version: 1.0.2 final Python Version: 2.5.2 Installed Applications: ['django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.sites', 'django.contrib.admin', 'django.contrib.admindocs', 'bisite'] Installed Middleware: ('django.middleware.common.CommonMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware') Traceback: File "/usr/lib/python2.5/site-packages/django/core/handlers/base.py" in get_response 86. response = callback(request, *callback_args, **callback_kwargs) File "/usr/lib/python2.5/site-packages/django/contrib/admin/sites.py" in root 157. return self.model_page(request, *url.split('/', 2)) File "/usr/lib/python2.5/site-packages/django/views/decorators/ cache.py" in _wrapped_view_func 44. response = view_func(request, *args, **kwargs) File "/usr/lib/python2.5/site-packages/django/contrib/admin/sites.py" in model_page 176. return admin_obj(request, rest_of_url) File "/usr/lib/python2.5/site-packages/django/contrib/admin/ options.py" in __call__ 195. return self.delete_view(request, unquote(url[:-7])) File "/usr/lib/python2.5/site-packages/django/contrib/admin/ options.py" in delete_view 679. get_deleted_objects(deleted_objects, perms_needed, request.user, obj, opts, 1, self.admin_site) File "/usr/lib/python2.5/site-packages/django/contrib/admin/util.py" in get_deleted_objects 107. nh(deleted_objects, current_depth, [u'%s: %s' % (force_unicode(capfirst(related.opts.verbose_name)), sub_obj), []]) Exception Type: TypeError at /admin/bisite/testcase/20/delete/ Exception Value: coercing to Unicode: need string or buffer, int found but deleting a "job" works just fine. You can see from my testcase model that it does in fact return a string (test_name) I have the following models: class Testcase(models.Model): test_id = models.AutoField(primary_key=True) test_name = models.CharField(max_length=300) src = models.ForeignKey(Source, null=True, blank=True) bitrate = models.IntegerField(null=True, blank=True) test_type = models.CharField(max_length=300) output_resolution = models.CharField(max_length=15, blank=True) description = models.CharField(max_length=3000, blank=True) ref_file = models.CharField(max_length=765, blank=True) ref_encode_filesize = models.IntegerField(null=True, blank=True) ref_y_psnr = models.DecimalField(null=True, max_digits=7, decimal_places=2, blank=True) ref_u_psnr = models.DecimalField(null=True, max_digits=7, decimal_places=2, blank=True) ref_v_psnr = models.DecimalField(null=True, max_digits=7, decimal_places=2, blank=True) ref_yuv_psnr = models.DecimalField(null=True, max_digits=7, decimal_places=2, blank=True) highmark_version = models.CharField(max_length=60, blank=True) def __unicode__(self): return self.test_name class Meta: ordering = ['test_name'] db_table = u'testcase' class Job(models.Model): job_id = models.AutoField(primary_key=True) job_name = models.CharField(max_length=50) server = models.CharField(max_length=25) minute = models.CharField(max_length=10, choices = u.min_choices()) hour = models.CharField(max_length=10, choices = u.hour_choices()) day_of_month = models.CharField(max_length=10, choices = u.dom_choices()) month = models.CharField(max_length=10, choices = u.mon_choices()) day_of_week = models.CharField( max_length=10, choices = u.dow_choices(), help_text = '* If Day of Week is selected, \ Day of Month and Month will be ignored.') logfile_name = models.CharField(max_length=100) new_code = models.BooleanField( help_text = '* Check out new code and compile before running tests.') base_dir = models.CharField( max_length=100, help_text = '* Directory to check code into.') svn_dir = models.CharField(max_length=100, help_text = '* SVN directory to check code out of.') test_dir = models.CharField(max_length=100, help_text = '* Directory to store test files in.') profile =
insert into data field of model based on other data field values
I am trying to figure out the best way to go about this. Here is the scenario: I have five fields in my model that the user will set from the admin. When they save the model I want to insert a value into another field of the model based on these values. Where/How is the best place to handle this. Here are the specifics: class Job(models.Model): job_id = models.AutoField(primary_key=True) job_name = models.CharField(max_length=50) server = models.CharField(max_length=25) minute = models.CharField(max_length=10, choices = u.min_choices()) hour = models.CharField(max_length=10, choices = u.hour_choices()) day_of_month = models.CharField(max_length=10, choices = u.dom_choices()) month = models.CharField(max_length=10, choices = u.mon_choices()) day_of_week = models.CharField(max_length=10, choices = u.dow_choices ()) next_run_time = models.DateTimeField(blank=True) What I want to do is based on the values of minute, hour, day_of_month, month and day_of_week I want to calculate the next_run_time and save that to the Job model. 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: Is it possible to 'order' the left side of a filter_horizontal?
Tim, The ordering meta option on my model did the trick. Thanks for the solution. Reed On Nov 25, 1:50 pm, Tim Valenta <tonightslasts...@gmail.com> wrote: > Well, you've got a couple of options. One is easiest and most > straightforward, but could impact performance. The second is a little > bit more work, but would limit the ordering to only taking effect on > that one form. > > The first way is to use the Meta option `ordering = ('fieldname',)`, > as described > here:http://docs.djangoproject.com/en/dev/ref/models/options/#ordering > > Bare in mind that this will passively affect ALL queries you do to > that model's objects, unless you specifically tell it not to order > during the query. If you think that you'll *always* want that sort > order to take effect, then this is the preferred method of > accomplishing that. > > The second way is to intercept the form's queryset powering the > widget. If you're not using Form objects with your admin (ie, you're > just specifying 'fields' or 'fieldsets' on your ModelAdmin), then > you'll have to take a quick sidequest: > > Create a class somewhere (preferably in your app's directory, in a > "forms.py" file or something obvious) like so: > > from django import forms > from models import MyModel > class MyModelForm(forms.ModelForm): > class Meta: > model = MyModel > def __init__(self, *args, **kwargs): > forms.ModelForm.__init__(self, *args, **kwargs) > self.fields['myfieldname'].queryset = > MyModel.objects.order_by('custom_sort_field_name') > > And then back in your ModelAdmin, add this attribute to the class: > > # ... > from forms import MyModelForm > form = MyModelForm > > This will cause the admin to use *your* form instead of the default. > What I've done is created a form which simply hijacks the queryset on > 'myfieldname' (the field you're trying to sort), and alters it before > the widget has a chance to render itself. > > Both methods are effective, but be sure to consider my initial > statement, about performance impact. Pick the method that strikes the > balance in your mind between performance and practicality. > > Hope that helps! > > On Nov 25, 1:06 pm, rc <reedcr...@gmail.com> wrote: > > > I have configured a modeladmin which uses the filter_horizontal > > feature. I would like to be able to order left side of this feature by > > name instead of the default (which I believe is by id). Is this > > possible? I see how to use "ordering" in the display for change lists, > > but not sure how to apply that to the 'left' side data of the > > filter_horizontal. -- 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.
Is it possible to 'order' the left side of a filter_horizontal?
I have configured a modeladmin which uses the filter_horizontal feature. I would like to be able to order left side of this feature by name instead of the default (which I believe is by id). Is this possible? I see how to use "ordering" in the display for change lists, but not sure how to apply that to the 'left' side data of the filter_horizontal. -- 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: Configure multi-field multi-select form in Django Admin
Tim, Thanks for the response. That is what I was looking for. I got it working now, just needed a little hint. Found the User Admin stuff (in contrib) and was able to follow that. As far as the "id" columns.I adapted Django to an existing system so that is why the models don't necessarily match the Django norm. Reed On Nov 24, 7:41 pm, Tim Valenta <tonightslasts...@gmail.com> wrote: > > The javascript will be found somewhere under django/contrib/admin/media/js. > > To be clear, rc, although the javascript is of course available for > viewing, you should only need to put that attribute > "filter_horizontal" on your ModelAdmin. There shouldn't be any need > for inserting any custom javascript commands anywhere. That one > attribute does it all. > > And... this might pose a problem, but I don't see any ManyToManyFields > in your models. It won't work unless you're using those, instead of > ForeignKeys. > > For the extra mile, you shouldn't need those various "_id = > models.AutoField(primary_key=True)" parts. Django does that > automatically, but names each one just "id", instead of "[modelname] > _id". Unless you specifically want them to be named differently than > "id", you don't have to specify it, which helps it be more readable. > But it's of course your own project :) Do it however you wish! > > Tim > > On Nov 24, 6:01 pm, Karen Tracey <kmtra...@gmail.com> wrote: > > > On Tue, Nov 24, 2009 at 12:32 PM, rc <reedcr...@gmail.com> wrote: > > > As I mentioned, the Django admin has exactly what I want with the user > > > permission form (auth_user, auth_permissions and > > > auth_user_user_permission). Does anyone know where that code is > > > located in the Django environment? > > > That's done with javascript, activated by listing the fields in: > > >http://docs.djangoproject.com/en/dev/ref/contrib/admin/#django.contri... > > > The javascript will be found somewhere under django/contrib/admin/media/js. > > > 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.
Re: Configure multi-field multi-select form in Django Admin
As I mentioned, the Django admin has exactly what I want with the user permission form (auth_user, auth_permissions and auth_user_user_permission). Does anyone know where that code is located in the Django environment? On Nov 24, 10:13 am, rc <reedcr...@gmail.com> wrote: > What I want to do is have a form with one field that allows you to > select a profile. Once this profile is selected there will be two > windows below that show available tests and selected tests. The Django > admin interface for the user permissions uses this format. Not sure > what it is called in Django. > > My current models are listed below. I have a joining table called > Testsuite that joins tests to profiles. It works now, but the admin is > not very easy to add or remove tests to a testsuite since you have to > add one at a time. If someone can point me in the right direction I > would appreciate it. > > Anyway I have the following models: > --- > Models > -- > > class Profile(models.Model): > profile_id = models.AutoField(primary_key=True) > profile_name = models.CharField(max_length=75) > description = models.CharField(max_length=1500, blank=True) > def __unicode__(self): > return self.profile_name > class Meta: > db_table = u'profile' > > class Testcase(models.Model): > test_id = models.AutoField(primary_key=True) > test_name = models.CharField(max_length=300) > src = models.ForeignKey(Source, null=True, blank=True) > bitrate = models.IntegerField(null=True, blank=True) > test_type = models.CharField(max_length=300) > output_resolution = models.CharField(max_length=15, blank=True) > description = models.CharField(max_length=3000, blank=True) > ref_file = models.CharField(max_length=765, blank=True) > ref_encode_filesize = models.IntegerField(null=True, blank=True) > ref_y_psnr = models.DecimalField(null=True, max_digits=7, > decimal_places=2, blank=True) > ref_u_psnr = models.DecimalField(null=True, max_digits=7, > decimal_places=2, blank=True) > ref_v_psnr = models.DecimalField(null=True, max_digits=7, > decimal_places=2, blank=True) > ref_yuv_psnr = models.DecimalField(null=True, max_digits=7, > decimal_places=2, blank=True) > highmark_version = models.CharField(max_length=60, blank=True) > def __unicode__(self): > return self.test_name > class Meta: > db_table = u'testcase' > > class Testsuite(models.Model): > testsuite_id = models.AutoField(primary_key=True) > profile = models.ForeignKey(Profile, related_name='profile') > test = models.ForeignKey(Testcase, related_name='test') > #def __unicode__(self): > # return > self.testsuite_id > def __unicode__(self): > return '%s,%s' % (self.profile, self.test) > class Meta: > db_table = u'testsuite' -- 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.
Configure multi-field multi-select form in Django Admin
What I want to do is have a form with one field that allows you to select a profile. Once this profile is selected there will be two windows below that show available tests and selected tests. The Django admin interface for the user permissions uses this format. Not sure what it is called in Django. My current models are listed below. I have a joining table called Testsuite that joins tests to profiles. It works now, but the admin is not very easy to add or remove tests to a testsuite since you have to add one at a time. If someone can point me in the right direction I would appreciate it. Anyway I have the following models: --- Models -- class Profile(models.Model): profile_id = models.AutoField(primary_key=True) profile_name = models.CharField(max_length=75) description = models.CharField(max_length=1500, blank=True) def __unicode__(self): return self.profile_name class Meta: db_table = u'profile' class Testcase(models.Model): test_id = models.AutoField(primary_key=True) test_name = models.CharField(max_length=300) src = models.ForeignKey(Source, null=True, blank=True) bitrate = models.IntegerField(null=True, blank=True) test_type = models.CharField(max_length=300) output_resolution = models.CharField(max_length=15, blank=True) description = models.CharField(max_length=3000, blank=True) ref_file = models.CharField(max_length=765, blank=True) ref_encode_filesize = models.IntegerField(null=True, blank=True) ref_y_psnr = models.DecimalField(null=True, max_digits=7, decimal_places=2, blank=True) ref_u_psnr = models.DecimalField(null=True, max_digits=7, decimal_places=2, blank=True) ref_v_psnr = models.DecimalField(null=True, max_digits=7, decimal_places=2, blank=True) ref_yuv_psnr = models.DecimalField(null=True, max_digits=7, decimal_places=2, blank=True) highmark_version = models.CharField(max_length=60, blank=True) def __unicode__(self): return self.test_name class Meta: db_table = u'testcase' class Testsuite(models.Model): testsuite_id = models.AutoField(primary_key=True) profile = models.ForeignKey(Profile, related_name='profile') test = models.ForeignKey(Testcase, related_name='test') #def __unicode__(self): # return self.testsuite_id def __unicode__(self): return '%s,%s' % (self.profile, self.test) class Meta: db_table = u'testsuite' -- 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.
Configuring a multiselect field in django admin
I am fairly new to Django and I am trying to get a few things working in Django Admin. I have the models shown below. I have a profile table and a test table. I have a joining table called testsuite which allows me to map multiple tests to a profile. This all works fine, but in the admin part I have to add one profile/test at a time. What I want to be able to do is select a profile and select multiple tests and add them at the same time. I would also like to be able to select a profile and see the test already assigned to it and be able to edit them and add or remove tests. Is it possible to do this? My admin file looks like this. Just the basic register lines. --- Admin --- from django.contrib import admin from bisite.models import Testcase, Testsuite, Profile, Source admin.site.register(Profile) admin.site.register(Source) admin.site.register(Testcase) admin.site.register(Testsuite) --- Models -- class Profile(models.Model): profile_id = models.AutoField(primary_key=True) profile_name = models.CharField(max_length=75) description = models.CharField(max_length=1500, blank=True) def __unicode__(self): return self.profile_name class Meta: db_table = u'profile' class Testcase(models.Model): test_id = models.AutoField(primary_key=True) test_name = models.CharField(max_length=300) src = models.ForeignKey(Source, null=True, blank=True) bitrate = models.IntegerField(null=True, blank=True) test_type = models.CharField(max_length=300) output_resolution = models.CharField(max_length=15, blank=True) description = models.CharField(max_length=3000, blank=True) ref_file = models.CharField(max_length=765, blank=True) ref_encode_filesize = models.IntegerField(null=True, blank=True) ref_y_psnr = models.DecimalField(null=True, max_digits=7, decimal_places=2, blank=True) ref_u_psnr = models.DecimalField(null=True, max_digits=7, decimal_places=2, blank=True) ref_v_psnr = models.DecimalField(null=True, max_digits=7, decimal_places=2, blank=True) ref_yuv_psnr = models.DecimalField(null=True, max_digits=7, decimal_places=2, blank=True) highmark_version = models.CharField(max_length=60, blank=True) def __unicode__(self): return self.test_name class Meta: db_table = u'testcase' class Testsuite(models.Model): testsuite_id = models.AutoField(primary_key=True) profile = models.ForeignKey(Profile, related_name='profile') test = models.ForeignKey(Testcase, related_name='test') #def __unicode__(self): # return self.testsuite_id def __unicode__(self): return '%s,%s' % (self.profile, self.test) class Meta: db_table = u'testsuite' -- 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=.
Re: how to do a three table join with django models
I figured it out. The model uses a "different" name for the foreign key. In my instance test is results FK to testcase. I changed it to Results.objects.all().select_related('profile','test') and worked. Thanks for your help. On Feb 5, 10:48 am, rc <reedcr...@gmail.com> wrote: > That worked great for the results and profile model, but I couldn't > get it to return any data from the testcase model?? > > My view > def get_results(request): > results_list = Results.objects.all().select_related > ('profile','testcase') > return render_to_response('biatf/index.html',{"results_list" : > results_list}) > > My template: > > {% if results_list %} > > {% for results in results_list %} > > name="result_id"value="{{ results.result_id }}" > {{ results.date }} > {{ results.profile.name }} > {{ results.testcase.test_name }} > > {% endfor %} > > > {% else %} > No results are available. > {% endif %} > > > On Feb 5, 9:41 am, felix <crucialfe...@gmail.com> wrote: > > > Results.objects.all().select_related('profile','testcase') > > > that was easy > > > that's A join B,C > > > if it was A join B join C > > > (my example) > > > class Release > > fk Artist > > > class Artist > > fk Label > > > class Label > > > Release.objects.all().select_related('artist','artist_label') > > > note selecting the C class via the B class 'B_C' > > > On Thu, Feb 5, 2009 at 5:28 PM, Daniel Roseman < > > > roseman.dan...@googlemail.com> wrote: > > > > On Feb 5, 3:50 pm, rc <reedcr...@gmail.com> wrote: > > > > I am newbie to Django and I am struggling to get my arms around DJango > > > > and it's data access api (models). > > > > > I have these models: > > > > > class Profile(models.Model): > > > > profile_id = models.AutoField(primary_key=True) > > > > profile_name = models.CharField(max_length=75) > > > > def __unicode__(self): > > > > return self.profile_id > > > > def __unicode__(self): > > > > return self.profile_name > > > > class Meta: > > > > db_table = 'profile' > > > > > class Testcase(models.Model): > > > > test_id = models.AutoField(primary_key=True) > > > > test_name = models.CharField(max_length=300) > > > > src = models.ForeignKey(Source, null=True, blank=True) > > > > bitrate = models.IntegerField(null=True, blank=True) > > > > test_type = models.CharField(max_length=300) > > > > output_resolution = models.CharField(max_length=15, blank=True) > > > > def __unicode__(self): > > > > return self.test_name > > > > class Meta: > > > > db_table = 'testcase' > > > > > class Results(models.Model): > > > > result_id = models.AutoField(primary_key=True) > > > > date = models.DateTimeField() > > > > test = models.ForeignKey(Testcase) > > > > profile = models.ForeignKey(Profile) > > > > status = models.CharField(max_length=30) > > > > graph = models.BlobField(null=True, blank=True) > > > > y_psnr = models.DecimalField(null=True, max_digits=5, > > > > decimal_places=2, blank=True) > > > > u_psnr = models.DecimalField(null=True, max_digits=5, > > > > decimal_places=2, blank=True) > > > > v_psnr = models.DecimalField(null=True, max_digits=5, > > > > decimal_places=2, blank=True) > > > > yuv_psnr = models.DecimalField(null=True, max_digits=5, > > > > decimal_places=2, blank=True) > > > > def __unicode__(self): > > > > return self.result_id > > > > class Meta: > > > > db_table = 'results' > > > > > and I want to be able to display this data: > > > > > select result_id, date, profile_name, test_name, status, y_psnr, > > > > u_psnr, v_psnr, yuv_psnr > > > > from profile, testcase, results > > > > where profile.profile_id = results.profile_id > > > > and testcase.test_id = results.
Re: how to do a three table join with django models
That worked great for the results and profile model, but I couldn't get it to return any data from the testcase model?? My view def get_results(request): results_list = Results.objects.all().select_related ('profile','testcase') return render_to_response('biatf/index.html',{"results_list" : results_list}) My template: {% if results_list %} {%for results in results_list %} {{ results.date }} {{ results.profile.name }} {{ results.testcase.test_name }} {% endfor %} {% else %} No results are available. {% endif %} On Feb 5, 9:41 am, felix <crucialfe...@gmail.com> wrote: > Results.objects.all().select_related('profile','testcase') > > that was easy > > that's A join B,C > > if it was A join B join C > > (my example) > > class Release > fk Artist > > class Artist > fk Label > > class Label > > Release.objects.all().select_related('artist','artist_label') > > note selecting the C class via the B class 'B_C' > > On Thu, Feb 5, 2009 at 5:28 PM, Daniel Roseman < > > roseman.dan...@googlemail.com> wrote: > > > On Feb 5, 3:50 pm, rc <reedcr...@gmail.com> wrote: > > > I am newbie to Django and I am struggling to get my arms around DJango > > > and it's data access api (models). > > > > I have these models: > > > > class Profile(models.Model): > > > profile_id = models.AutoField(primary_key=True) > > > profile_name = models.CharField(max_length=75) > > > def __unicode__(self): > > > return self.profile_id > > > def __unicode__(self): > > > return self.profile_name > > > class Meta: > > > db_table = 'profile' > > > > class Testcase(models.Model): > > > test_id = models.AutoField(primary_key=True) > > > test_name = models.CharField(max_length=300) > > > src = models.ForeignKey(Source, null=True, blank=True) > > > bitrate = models.IntegerField(null=True, blank=True) > > > test_type = models.CharField(max_length=300) > > > output_resolution = models.CharField(max_length=15, blank=True) > > > def __unicode__(self): > > > return self.test_name > > > class Meta: > > > db_table = 'testcase' > > > > class Results(models.Model): > > > result_id = models.AutoField(primary_key=True) > > > date = models.DateTimeField() > > > test = models.ForeignKey(Testcase) > > > profile = models.ForeignKey(Profile) > > > status = models.CharField(max_length=30) > > > graph = models.BlobField(null=True, blank=True) > > > y_psnr = models.DecimalField(null=True, max_digits=5, > > > decimal_places=2, blank=True) > > > u_psnr = models.DecimalField(null=True, max_digits=5, > > > decimal_places=2, blank=True) > > > v_psnr = models.DecimalField(null=True, max_digits=5, > > > decimal_places=2, blank=True) > > > yuv_psnr = models.DecimalField(null=True, max_digits=5, > > > decimal_places=2, blank=True) > > > def __unicode__(self): > > > return self.result_id > > > class Meta: > > > db_table = 'results' > > > > and I want to be able to display this data: > > > > select result_id, date, profile_name, test_name, status, y_psnr, > > > u_psnr, v_psnr, yuv_psnr > > > from profile, testcase, results > > > where profile.profile_id = results.profile_id > > > and testcase.test_id = results.test_id > > > > Which is very easy to do with raw sql, but struggling to do it the > > > "django' way. > > > > Any ideas? > > > I have also tried to use raw sql, but struggled to get it to work in > > > my views and templates. > > > The Django ORM is there to help you. If you don't find it easy, don't > > use it. However, the simple way of doing it would be something like > > this: > > > for testcase in Testcase.objects.all(): > > print testcase.status > > for result in testcase.result_set.all(): > > print result.result_id, result.date, > > result.profile.profile_name, \ > > result.status, result.y_psnr, \ > > result.u_psnr, result.v_psnr, result.yuv_psnr &
how to do a three table join with django models
I am newbie to Django and I am struggling to get my arms around DJango and it's data access api (models). I have these models: class Profile(models.Model): profile_id = models.AutoField(primary_key=True) profile_name = models.CharField(max_length=75) def __unicode__(self): return self.profile_id def __unicode__(self): return self.profile_name class Meta: db_table = 'profile' class Testcase(models.Model): test_id = models.AutoField(primary_key=True) test_name = models.CharField(max_length=300) src = models.ForeignKey(Source, null=True, blank=True) bitrate = models.IntegerField(null=True, blank=True) test_type = models.CharField(max_length=300) output_resolution = models.CharField(max_length=15, blank=True) def __unicode__(self): return self.test_name class Meta: db_table = 'testcase' class Results(models.Model): result_id = models.AutoField(primary_key=True) date = models.DateTimeField() test = models.ForeignKey(Testcase) profile = models.ForeignKey(Profile) status = models.CharField(max_length=30) graph = models.BlobField(null=True, blank=True) y_psnr = models.DecimalField(null=True, max_digits=5, decimal_places=2, blank=True) u_psnr = models.DecimalField(null=True, max_digits=5, decimal_places=2, blank=True) v_psnr = models.DecimalField(null=True, max_digits=5, decimal_places=2, blank=True) yuv_psnr = models.DecimalField(null=True, max_digits=5, decimal_places=2, blank=True) def __unicode__(self): return self.result_id class Meta: db_table = 'results' and I want to be able to display this data: select result_id, date, profile_name, test_name, status, y_psnr, u_psnr, v_psnr, yuv_psnr from profile, testcase, results where profile.profile_id = results.profile_id and testcase.test_id = results.test_id Which is very easy to do with raw sql, but struggling to do it the "django' way. Any ideas? I have also tried to use raw sql, but struggled to get it to work in my views and templates. --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---