djangojs translations not available
Hi, I have a djangojs.po file and am compiling the messages with compilemessages command. I don't get any error but I can't see my translations in the js catalog. I can only see the admin js translations. How can I debug this problem? Thanks in advance. -- 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: djangojs translations not available
So, I managed to fix the problem. If some has the same problem here are some useful infos: - if you have a normal setting.py file then you should not have this problem with djangojs domain translations - if you have your settings.py file split into several sub-settings the locale directory should be inside an application in order to be loaded OR you can define the LOCALE_PATHS variable pointing to it in settings BUT in the second case the djangojs domain translations wont work, see ticket http://code.djangoproject.com/ticket/5494 So, in this last case, the solution will be to pass the locale with the djangojs domain files to one of the installed apps and it will work :) I hope this helps people with similar problems. On May 20, 12:17 pm, filias wrote: > Hi, > > I have a djangojs.po file and am compiling the messages with > compilemessages command. > I don't get any error but I can't see my translations in the js > catalog. I can only see the admin js translations. > > How can I debug this problem? > > Thanks in advance. > > -- > 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 > athttp://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-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.
Change language when user logs into admin
Hi, I want to change the language code to english everytime the user logs into the admin site. What is the best way to do it? Can I extend the initial admin view? Thanks in advance, -- 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 translating form fields
Hi, we have several django applications in the same project and in one of them, for some reason, we can't get the translated name for the model form fields. We have no idea why this application doesn't behave like the other ones. In order to see the translated label for the modelform field we have to explicitly set the label attribute in the modelform field. This doesn't make sense because we are using the default fields from modelform and therefore we believe the verbose_name attribute from the model field should be used (and it is in the other applications). We are out of ideas on why this happens and decided to post here the problem. Maybe one of you has an idea about this. Thanks in advance. -- 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.
Do fixtures in tests overwrite default model field values?
Hi, I am running several tests and created a fixture with the test data. I have one model with a custom field which has a default value. I thought my test fixture should overwrite this field for some of the objects but when run the test the value for the field is always the default value. Is this the normal behavior or do I have some bug in my custom field? 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.
Organizing a model's properties and methods - best practices
Hi, I have a model which starts to have "too many" properties and methods. I dont know if this is normal or if there are better ways to deal with increasing complexity of a model. In the beginning there were just 4 or 5 properties and methods but with the news demands of the app they started to grow. I am afraid this becomes unreadable and "too big". I would like to read about your best practices related to this topic: having a model with lots of properties and methods. 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.
django-test-coverage gcc error
I am trying to use a test coverage tool for django. I tried http://pypi.python.org/pypi/django-test-coverage/0.1. First with easy_install and after with setup.py install and I get the following error stack: Searching for django-test-coverage Best match: django-test-coverage 0.1 Processing django_test_coverage-0.1-py2.6.egg django-test-coverage 0.1 is already the active version in easy- install.pth Using /usr/local/lib/python2.6/dist-packages/django_test_coverage-0.1- py2.6.egg Processing dependencies for django-test-coverage Searching for coverage Reading http://pypi.python.org/simple/coverage/ Reading http://nedbatchelder.com/code/modules/coverage.html Reading http://nedbatchelder.com/code/coverage Best match: coverage 3.3.1 Downloading http://pypi.python.org/packages/source/c/coverage/coverage-3.3.1.tar.gz#md5=6f5a25ce06baad03ab293990f3a98bb7 Processing coverage-3.3.1.tar.gz Running coverage-3.3.1/setup.py -q bdist_egg --dist-dir /tmp/ easy_install-nzgKke/coverage-3.3.1/egg-dist-tmp-JgaYFe no previously-included directories found matching 'test' coverage/tracer.c:3:20: error: Python.h: No such file or directory coverage/tracer.c:4:71: error: compile.h: No such file or directory coverage/tracer.c:5:43: error: eval.h: No such file or directory coverage/tracer.c:6:26: error: structmember.h: No such file or directory coverage/tracer.c:7:25: error: frameobject.h: No such file or directory coverage/tracer.c:49: error: expected specifier-qualifier-list before ‘PyObject’ coverage/tracer.c:56: error: expected specifier-qualifier-list before ‘PyObject_HEAD’ coverage/tracer.c:115: error: expected declaration specifiers or ‘...’ before ‘PyObject’ coverage/tracer.c:115: error: expected declaration specifiers or ‘...’ before ‘PyObject’ coverage/tracer.c: In function ‘Tracer_init’: coverage/tracer.c:129: error: ‘Tracer’ has no member named ‘should_trace’ coverage/tracer.c:129: error: ‘NULL’ undeclared (first use in this function) coverage/tracer.c:129: error: (Each undeclared identifier is reported only once coverage/tracer.c:129: error: for each function it appears in.) coverage/tracer.c:130: error: ‘Tracer’ has no member named ‘data’ coverage/tracer.c:131: error: ‘Tracer’ has no member named ‘should_trace_cache’ coverage/tracer.c:132: error: ‘Tracer’ has no member named ‘arcs’ coverage/tracer.c:134: error: ‘Tracer’ has no member named ‘started’ coverage/tracer.c:135: error: ‘Tracer’ has no member named ‘tracing_arcs’ coverage/tracer.c:137: error: ‘Tracer’ has no member named ‘depth’ coverage/tracer.c:138: error: ‘Tracer’ has no member named ‘data_stack’ coverage/tracer.c:138: warning: implicit declaration of function ‘PyMem_Malloc’ coverage/tracer.c:139: error: ‘Tracer’ has no member named ‘data_stack’ coverage/tracer.c:141: warning: implicit declaration of function ‘PyErr_NoMemory’ coverage/tracer.c:144: error: ‘Tracer’ has no member named ‘data_stack_alloc’ coverage/tracer.c:146: error: ‘Tracer’ has no member named ‘cur_file_data’ coverage/tracer.c:147: error: ‘Tracer’ has no member named ‘last_line’ coverage/tracer.c:149: error: ‘Tracer’ has no member named ‘last_exc_back’ coverage/tracer.c: In function ‘Tracer_dealloc’: coverage/tracer.c:157: error: ‘Tracer’ has no member named ‘started’ coverage/tracer.c:158: warning: implicit declaration of function ‘PyEval_SetTrace’ coverage/tracer.c:158: error: ‘NULL’ undeclared (first use in this function) coverage/tracer.c:161: warning: implicit declaration of function ‘Py_XDECREF’ coverage/tracer.c:161: error: ‘Tracer’ has no member named ‘should_trace’ coverage/tracer.c:162: error: ‘Tracer’ has no member named ‘data’ coverage/tracer.c:163: error: ‘Tracer’ has no member named ‘should_trace_cache’ coverage/tracer.c:165: warning: implicit declaration of function ‘PyMem_Free’ coverage/tracer.c:165: error: ‘Tracer’ has no member named ‘data_stack’ coverage/tracer.c:167: error: ‘PyObject’ undeclared (first use in this function) coverage/tracer.c:167: error: expected expression before ‘)’ token coverage/tracer.c:167: error: expected ‘)’ before ‘self’ coverage/tracer.c: In function ‘Tracer_record_pair’: coverage/tracer.c:224: error: ‘PyObject’ undeclared (first use in this function) coverage/tracer.c:224: error: ‘t’ undeclared (first use in this function) coverage/tracer.c:224: warning: implicit declaration of function ‘PyTuple_New’ coverage/tracer.c:225: error: ‘NULL’ undeclared (first use in this function) coverage/tracer.c:226: warning: implicit declaration of function ‘PyTuple_SET_ITEM’ coverage/tracer.c:226: warning: implicit declaration of function ‘PyInt_FromLong’ coverage/tracer.c:228: warning: implicit declaration of function ‘PyDict_SetItem’ coverage/tracer.c:228: error: ‘Tracer’ has no member named ‘cur_file_data’ coverage/tracer.c:228: error: ‘Py_None’ undeclared (first use in this function) coverage/tracer.c:232: warning: implicit declaration of function ‘Py_DECREF’ coverage/tracer.c: At top level: coverage/tracer.c:245: error: expected declaration specifiers or
Re: django-test-coverage gcc error
Thanks Karen, I am using ubuntu karmic. I will search for the package that I need. On Mar 10, 4:34 pm, Karen Tracey wrote: > On Wed, Mar 10, 2010 at 11:13 AM, filias wrote: > > I am trying to use a test coverage tool for django. > > > I triedhttp://pypi.python.org/pypi/django-test-coverage/0.1. First > > with easy_install and after with setup.py install and I get the > > following error stack: > > > Searching for django-test-coverage > > Best match: django-test-coverage 0.1 > > Processing django_test_coverage-0.1-py2.6.egg > > django-test-coverage 0.1 is already the active version in easy- > > install.pth > > > Using /usr/local/lib/python2.6/dist-packages/django_test_coverage-0.1- > > py2.6.egg > > Processing dependencies for django-test-coverage > > Searching for coverage > > Readinghttp://pypi.python.org/simple/coverage/ > > Readinghttp://nedbatchelder.com/code/modules/coverage.html > > Readinghttp://nedbatchelder.com/code/coverage > > Best match: coverage 3.3.1 > > Downloading > >http://pypi.python.org/packages/source/c/coverage/coverage-3.3.1.tar > > Processing coverage-3.3.1.tar.gz > > Running coverage-3.3.1/setup.py -q bdist_egg --dist-dir /tmp/ > > easy_install-nzgKke/coverage-3.3.1/egg-dist-tmp-JgaYFe > > no previously-included directories found matching 'test' > > coverage/tracer.c:3:20: error: Python.h: No such file or directory > > [snip remainder] > > You don't have installed whatever package you need on your system to build > Python C extensions. What type of system is this? > > 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: django-test-coverage gcc error
ok. I installed python2.6-dev and it works now :) thanks again. On Mar 11, 11:50 am, filias wrote: > Thanks Karen, I am using ubuntu karmic. I will search for the package > that I need. > > On Mar 10, 4:34 pm, Karen Tracey wrote: > > > On Wed, Mar 10, 2010 at 11:13 AM, filias wrote: > > > I am trying to use a test coverage tool for django. > > > > I triedhttp://pypi.python.org/pypi/django-test-coverage/0.1. First > > > with easy_install and after with setup.py install and I get the > > > following error stack: > > > > Searching for django-test-coverage > > > Best match: django-test-coverage 0.1 > > > Processing django_test_coverage-0.1-py2.6.egg > > > django-test-coverage 0.1 is already the active version in easy- > > > install.pth > > > > Using /usr/local/lib/python2.6/dist-packages/django_test_coverage-0.1- > > > py2.6.egg > > > Processing dependencies for django-test-coverage > > > Searching for coverage > > > Readinghttp://pypi.python.org/simple/coverage/ > > > Readinghttp://nedbatchelder.com/code/modules/coverage.html > > > Readinghttp://nedbatchelder.com/code/coverage > > > Best match: coverage 3.3.1 > > > Downloading > > >http://pypi.python.org/packages/source/c/coverage/coverage-3.3.1.tar > > > Processing coverage-3.3.1.tar.gz > > > Running coverage-3.3.1/setup.py -q bdist_egg --dist-dir /tmp/ > > > easy_install-nzgKke/coverage-3.3.1/egg-dist-tmp-JgaYFe > > > no previously-included directories found matching 'test' > > > coverage/tracer.c:3:20: error: Python.h: No such file or directory > > > [snip remainder] > > > You don't have installed whatever package you need on your system to build > > Python C extensions. What type of system is this? > > > 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.
Overriding a form from another application
Hi, I have an application with a model and a modelform. I have another application and in a a specific case I would like to override one attribute from the modelform in the original application. Example: class Article(models.Model): identifier: = models.CharField(max_length=10) headline = models.CharField(max_length=100) publications = models.ManyToManyField(Publication) class ArticleForm(ModelForm): class Meta: model = Article def add(request): form = ArticleForm(request.POST or None) if request.POST and form.is_valid(): instance = form.save() return HttpResponseRedirect(reverse("add-article", args=[instance.pk])) else: errors = form.errors context = { 'form': form, 'request': request } return render_to_response('article/add.html', context) Now I have another application that uses the articles application but in another way so that the identifier is not used and should not appear in the form to add an Article. What is the best way to do it? I considered 2 things: 1 - make the view a class and override the form attribute in the new application. 2 - make the form an attribute of the view function and override it in the new application Am I thinking correctly? What are the best practices on this topic? 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.
Internationalization problem - translations not appearing
Hi, I have a project with several applications. The translations to another language are located in /locale I used the makemessages command (run from the project directory) to generate the .po file and all the marked strings from code and templates appear in the file. I used the compilemessages command (run from the project directory) to generate the .mo file. The result is that my translations dont appear in the website. I think the .mo files in the locale directory under my project dir are not being read but I dont know why. I know from the documentation what is the order in which the translations are discovered and I think my project directory locale was not being read. Therefore I added a LOCALE_PATHS variable to my settings with the path to this locale (I tried relative and absolute paths). Still nothing appears. After I tried to crete the local just for one of my applications and it worked but I do not want to have a locale dir for each application, I want to have all the translations in just one file in the project dir. Does someone have an idea of how to solve this problem? Thanks in advance. -- 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: Internationalization problem - translations not appearing
Ok, I managed to fix it with LOCALE_PATHS. Example: LOCALE_PATHS = ('', '/locale') I hope it helps someone :) On Mar 24, 4:22 pm, filias wrote: > Hi, > > I have a project with several applications. The translations to > another language are located in /locale > > I used the makemessages command (run from the project directory) to > generate the .po file and all the marked strings from code and > templates appear in the file. > > I used the compilemessages command (run from the project directory) to > generate the .mo file. > > The result is that my translations dont appear in the website. I think > the .mo files in the locale directory under my project dir are not > being read but I dont know why. > > I know from the documentation what is the order in which the > translations are discovered and I think my project directory locale > was not being read. Therefore I added a LOCALE_PATHS variable to my > settings with the path to this locale (I tried relative and absolute > paths). Still nothing appears. > > After I tried to crete the local just for one of my applications and > it worked but I do not want to have a locale dir for each application, > I want to have all the translations in just one file in the project > dir. > > Does someone have an idea of how to solve this problem? > > Thanks in advance. -- 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.
Extending the admin - add 'save and go to next' button
Hi, I want to extend the admin by adding a 'Save/Next' button next to the default 'Save' button. This action would save the instance and show the next instance (if it exists) or go back to the list. What is the best way to do it? Is there any post on best practices on these topic or other admin customizations? Thanks in advance. -- 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.
Not translating the admin
Hi, I have an application in several languages but I would like to keep the admin site always in english. What is the best way to do this? Thanks in advance. -- 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.
Get the value of a bound field in admin
Hi, how can I get the value of a bound field in django admin? I am extending some functionalities in the admin and I would like to be able to show something according to the field value. I want to do this in the change_form.html or fieldset.html files, so in the template. How can I get access to the value of a field? I think this topic is explored in this ticket: http://code.djangoproject.com/ticket/10427 Thanks in advance. -- 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.
Using properties as filters in the admin
Hi, I would like to know if it is possible to use properties as filters in the admin site. I have a model with a property and would like to use this property as a filter. As far as I read in the documentation one can only use attributes as filters but I would like to know if there is any workaround or any advices in this topic. Thanks in advance. -- 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: Using properties as filters in the admin
Humm, but are not FilterSpecs used to customized a filter on a specific attribute of the model? In my case I would like that the value of a property is used as a filter in the admin. This property is not related directly with any of the fields from the model. Is there a way of doing this? On Apr 12, 9:42 pm, shane wrote: > You could try a custom filter_spec. > > Examples @http://www.djangosnippets.org/tags/filterspec/ -- 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.
Adding unique_together attribute after database is created
Hi, I would like to add the unique_together attribute of the Meta class for a model in my app. My question is: my database already exists with several records, it is possible to just add the attribute and not do anything in the database level? does it work? I have tried in a app using sqlite and another using postgres and it worked. But I just wanted to get some confirmation. I believe it does not affect the records I already have in the database but only the newly created ones, I am right? Is there any documentation page explaining this attribute in more detail? Thanks in advance. -- 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.
Not translating the admin
Hi, I have a project with several applications and I am using i18n. I would like to have everything translated except the admin. Is it somehow possible to select which apps are subject to the i18n middleware? Thanks for your help. -- 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.
Template filters and translations to russian language
Hi, I am developing a website in russian and the original is in english. We are using the po file to translate the strings. My problem now is that when I use template filters, for example date or localnaturalday the translations do not appear. Everything appears in english. However, if I change the LANGUAGE_CODE from 'ru' to 'de_DE' everything appears correctly in german. My settings are: LANGUAGES = (('ru', 'Russian'), ('en_US', 'English')) LANGUAGE_CODE = 'ru' What am I missing here? Thanks for the help. -- 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/-/kcXLJCgXu_4J. 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.
Django admin forms - using a different/unconventional widget for a field
Hi, I have a DateTimeField in my model but I want to show with a CheckboxInput. We have a DateTime field in the model because we want to save the datetime when the instance was cancelled but we dont want the user to see that and just check or uncheck the cancellation checkbox. I already overrode the save method of the form to transform the boolean of the checkbox into datetime.now() but I also need the vice-versa: to show the checkbox checked or unchecked according to the presence or not of a date. How can I do that? Thanks in advance. -- 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/-/dzV_9mxKvWsJ. 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 admin forms - using a different/unconventional widget for a field
Perfect! Thanks a lot alan :) On Monday, September 3, 2012 3:28:29 PM UTC+2, zayatzz wrote: > > In form, that displays the checkbox do something like this: > def __init__(self, *args, **kwargs): > super(FormName, self).(*args, **kwargs) > if self.instance and self.instance.checkboxfieldname != None: #we > check if this form has instance and if checkbox : > attrs = {'checked':'checked'} > else: > attrs = {} > self.fields['checkboxfieldname'] = forms.BooleanField(widget = > forms.CheckboxInput(attrs = attrs)) > > should work. > alan > -- 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/-/bZp6I1iKnHUJ. 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.
Bi-directional ManyToMany with through gets broken when creating test database
Hi, I have recently upgraded to sjango 1.8 and I have 2 models with a bi-directional ManyToMany field. It looks like this class Pizza(Model): available_toppings = ManyToManyField('Topping') class Topping(Model): all_pizzas = ManyToManyField(Pizza, through=Pizza.available_stoppings.through, verbose_name='available pizzas') Everything was fine in django 1.7 but right now when running tests, specifically when creating the test database, I get this exception: self = def execute(self, query, params=None): if params is None: > return Database.Cursor.execute(self, query) E OperationalError: table "products_pizza_available_toppings" already exists So it looks like the creation of the test database is trying to re-create the intermediate table for the ManyToMany. I do not get any exception when running my site. Does anyone know how can I fix this? Thank you in advance -- 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/4b8bb3c4-c0bd-4315-9cb6-004db2fa2355%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: Bi-directional ManyToMany with through gets broken when creating test database
Indeed something in the project's code must be wrong but it is not the bi-directional ManyToMany as this has been working in django 1.4, 1.5, 1.6 and 1.7. One might want to had the ManyToMany in both models so to be able to add more information, as it is stated in the django docs https://docs.djangoproject.com/en/1.9/topics/db/models/#extra-fields-on-many-to-many-relationships in my case I just want the field to have a different name. I am thinking of using a property but I got into some troubles with my code when I did that, specifically the migration to remove the all_pizzas field crashes. I have created a new project with only those 2 models and it seems to work correctly, so the problem is somehow related to our test runner (py.test) and something else which I still don't know. My models.py file looks like this: from django.db import models class Pizza(models.Model): available_toppings = models.ManyToManyField('Topping') class Topping(models.Model): all_pizzas = models.ManyToManyField(Pizza, through=Pizza.available_toppings.through, verbose_name='available pizzas') I will continue investigating. On Friday, December 4, 2015 at 11:31:19 AM UTC+1, Remco Gerlich wrote: > > One, from that error message alone I can't figure out what is happening > and why when you run tests, so I can't help there. > > But two: you don't have a ManyToManyField, you have TWO ManyToManyFields. > If you define a many to many field on one model, than it's automatically > also defined on the other (if you only have the one on Pizza, then you can > do topping.pizza_set.all() from the other side. > > So your current code is almost certainly wrong, but if these are your > exact models than I don't think they are related to your error. > > Remco > > On Fri, Dec 4, 2015 at 9:54 AM, filias > > wrote: > >> Hi, >> >> I have recently upgraded to sjango 1.8 and I have 2 models with a >> bi-directional ManyToMany field. It looks like this >> >> class Pizza(Model): >> available_toppings = ManyToManyField('Topping') >> >> class Topping(Model): >>all_pizzas = ManyToManyField(Pizza, >> through=Pizza.available_stoppings.through, verbose_name='available pizzas') >> >> Everything was fine in django 1.7 but right now when running tests, >> specifically when creating the test database, I get this exception: >> >> self = > 0x7fd24fca4b00> >> >> def execute(self, query, params=None): >> if params is None: >> >> > return Database.Cursor.execute(self, query) >> E OperationalError: table "products_pizza_available_toppings" >> already exists >> >> So it looks like the creation of the test database is trying to re-create >> the intermediate table for the ManyToMany. >> >> I do not get any exception when running my site. >> >> Does anyone know how can I fix this? >> >> Thank you in advance >> >> -- >> 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/4b8bb3c4-c0bd-4315-9cb6-004db2fa2355%40googlegroups.com >> >> <https://groups.google.com/d/msgid/django-users/4b8bb3c4-c0bd-4315-9cb6-004db2fa2355%40googlegroups.com?utm_medium=email&utm_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/0d982fc9-aebb-4430-aa56-28babd1fcee8%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: Bi-directional ManyToMany with through gets broken when creating test database
Hi Simon, thanks for your reply, I suspected exactly what you said. I am not sure, this is not my code so I am not aware of the reason for this but I will try to refactor it the way you suggest. Cheers, filipa On Friday, December 4, 2015 at 4:38:41 PM UTC+1, Simon Charette wrote: > > Hi filias, > > I personally didn't know one could define a reverse foreign key this way > and > I doubt this use case is covered by the test suite. I'm afraid it worked > for > Django < 1.8 by chance since it's not documented you can re-use the > implicitly created intermediary model as a `through` argument. I suspect > this > might be due to the `_meta`[1] refactoring that happened in 1.8. > > May I ask you why you don't simply define a `related_name`[2] if you simply > want to have a different reverse relationship name? > > class Pizza(models.Model): > pass > > class Topping(models.Model): > all_pizzas = models.ManyToManyField( > Pizza, related_name='available_toppings', > verbose_name='available pizzas' > ) > > Cheers, > Simon > > [1] https://docs.djangoproject.com/en/1.8/releases/1.8/#model-meta-api > [2] > https://docs.djangoproject.com/en/1.8/ref/models/fields/#django.db.models.ManyToManyField.related_name > > Le vendredi 4 décembre 2015 07:08:51 UTC-5, filias a écrit : >> >> Indeed something in the project's code must be wrong but it is not the >> bi-directional ManyToMany as this has been working in django 1.4, 1.5, 1.6 >> and 1.7. One might want to had the ManyToMany in both models so to be able >> to add more information, as it is stated in the django docs >> https://docs.djangoproject.com/en/1.9/topics/db/models/#extra-fields-on-many-to-many-relationships >> >> in my case I just want the field to have a different name. I am thinking of >> using a property but I got into some troubles with my code when I did that, >> specifically the migration to remove the all_pizzas field crashes. >> >> I have created a new project with only those 2 models and it seems to >> work correctly, so the problem is somehow related to our test runner >> (py.test) and something else which I still don't know. >> >> My models.py file looks like this: >> from django.db import models >> >> >> class Pizza(models.Model): >> available_toppings = models.ManyToManyField('Topping') >> >> >> class Topping(models.Model): >>all_pizzas = models.ManyToManyField(Pizza, >> through=Pizza.available_toppings.through, verbose_name='available pizzas') >> >> I will continue investigating. >> >> On Friday, December 4, 2015 at 11:31:19 AM UTC+1, Remco Gerlich wrote: >>> >>> One, from that error message alone I can't figure out what is happening >>> and why when you run tests, so I can't help there. >>> >>> But two: you don't have a ManyToManyField, you have TWO >>> ManyToManyFields. If you define a many to many field on one model, than >>> it's automatically also defined on the other (if you only have the one on >>> Pizza, then you can do topping.pizza_set.all() from the other side. >>> >>> So your current code is almost certainly wrong, but if these are your >>> exact models than I don't think they are related to your error. >>> >>> Remco >>> >>> On Fri, Dec 4, 2015 at 9:54 AM, filias wrote: >>> >>>> Hi, >>>> >>>> I have recently upgraded to sjango 1.8 and I have 2 models with a >>>> bi-directional ManyToMany field. It looks like this >>>> >>>> class Pizza(Model): >>>> available_toppings = ManyToManyField('Topping') >>>> >>>> class Topping(Model): >>>>all_pizzas = ManyToManyField(Pizza, >>>> through=Pizza.available_stoppings.through, verbose_name='available pizzas') >>>> >>>> Everything was fine in django 1.7 but right now when running tests, >>>> specifically when creating the test database, I get this exception: >>>> >>>> self = >>> 0x7fd24fca4b00> >>>> >>>> def execute(self, query, params=None): >>>> if params is None: >>>> >>>> > return Database.Cursor.execute(self, query) >>>> E OperationalError: table "products_pizza_available_toppings" >>>> already exists >>>> >>>> So it looks like the creation of the