django-1.7

Models inside tests - Django 1.7 issue

旧时模样 提交于 2019-12-06 19:27:06
问题 I'm trying to port my project to use Django 1.7. Everything is fine except 1 thing. Models inside tests folders. Django 1.7 new migrations run migrate command internally. Before syncdb was ran. That means if a model is not included in migrations - it won't be populated to DB (and also to test DB). That's exactly what I'm experiencing right now. What I do is: In my /app/tests/models.py I have dummy model: class TestBaseImage(BaseImage): pass All it does is to inherit from an abstract BaseImage

Add a boolean field if a row exists in another table?

若如初见. 提交于 2019-12-06 14:30:17
I have two tables called Post and Reply . The users can create just one Response for each Post . The models look like this: class Post(models.Model): name = models.CharField(max_length = 100) class Reply(models.Model): post = models.ForeignKey(Post, related_name = 'replies') Now, I have a view that returns the posts, like this: class PostList(generics.ListAPIView): permission_classes = (permissions.IsAuthenticated,) queryset = Post.objects.all() serializer_class = PostSerializer And a serializer for the posts: class PostSerializer(serializers.ModelSerializer): class Meta: fields = ('id', 'name

Django translations of third party apps

风格不统一 提交于 2019-12-06 02:49:50
I'm trying to translate a Django third-party app ( django-recurrence ) within my Django 1.7 project. Despite all the answers I've been reading here about the same problem, I'm still being unable to have Django generate the django.po for this app. These are my current settings: settings.py LANGUAGE_CODE = 'it-IT' gettext = lambda s: s LANGUAGES = ( ('en-us', gettext('English')), ('it-it', gettext('Italian')), ) LOCALE_PATHS = ( '/home/seether/.virtualenvs/mytime/lib/python2.7/site-packages/recurrence/locale',) TIME_ZONE = 'Europe/Rome' USE_I18N = True USE_L10N = True I've tried modifying LOCALE

Longer username in Django 1.7

孤街醉人 提交于 2019-12-05 10:17:58
I want to increase the length of the username in django from 30 to around 80, I know it may be duplicate question but the previous answers are not working, for example https://kfalck.net/2010/12/30/longer-usernames-for-django this is for Django 1.2. Did anyone try similar hack for Django>1.5 Thanks in advance In Django 1.5 and above, the recommended approach would be to create a custom user model . Then you can make the username field exactly as you want. I had the same problem few days ago. Finally, I ended just with cutting off first 30 characters of the (old) username (into the new database

Upgrading transaction.commit_manually() to Django > 1.6

99封情书 提交于 2019-12-05 04:06:50
I have inherited some code for an app that was written for Django 1.4. We need to update the codebase to work with Django 1.7, and eventually 1.8 as the next Long Term Support release. In a few places it uses the old style @transaction.commit_manually and with transaction.commit_manually: I do not know enough about transactions in general but I am trying to understand what they are used for, so I can either remove them (if unnecessary) or upgrade them to the newer set_autocommit(False) or equivalent. I have understood that transaction management in Django < 1.5 was not ideal, and too

Django - custom admin page not related to a model

北慕城南 提交于 2019-12-05 02:55:57
问题 I am using Django 1.7 with Mezzanine. I would like to have some page in admin, where the staff can call some actions (management commands etc.) with buttons and other control elements. I would also like to avoid creating new model, or manually create a template and add link to it (if possible). What is the most common/clean ways how to achieve that? 回答1: Actually it is simpler. Just before urlpatterns in urls.py patch admin urls like that: def get_admin_urls(urls): def get_urls(): my_urls =

Models.DateField Format issues

感情迁移 提交于 2019-12-05 01:34:26
问题 I have a model, which has a date field date_of_birth = models.DateField(blank=True, null=True, verbose_name="DOB") I would like to format it to save dates in the format dd/MM/yyyy , but everything I have tried fails. I think the default must be YYYY-MM-dd because that is how it saves to my database. Trying to submit dates in a different format gives the error: [u"'17/01/1970' value has an invalid date format. It must be in YYYY-MM-DD format."] I have tried using Date Widgets but am having a

Django 1.7 makemigrations freezing/hanging

天涯浪子 提交于 2019-12-05 00:49:55
I'm finally upgrading from Django 1.6 to 1.7, and removing South in the process. I followed the official Django instructions and removed all my old numbered migrations. Now I'm trying to run python manage.py makemigrations to get the new migrations to continue moving forward with 1.7's migrations module, but it completely hangs and the only output I get is the following: bash -cl "/Users/me/.virtualenvs/mysite-Dj17/bin/python /Applications/PyCharm.app/Contents/helpers/pycharm/django_manage.py makemigrations /Users/me/Coding/mysite" /Users/me/.virtualenvs/mysite-Dj17/lib/python2.7/site-packages

Models inside tests - Django 1.7 issue

让人想犯罪 __ 提交于 2019-12-04 23:32:02
I'm trying to port my project to use Django 1.7. Everything is fine except 1 thing. Models inside tests folders. Django 1.7 new migrations run migrate command internally. Before syncdb was ran. That means if a model is not included in migrations - it won't be populated to DB (and also to test DB). That's exactly what I'm experiencing right now. What I do is: In my /app/tests/models.py I have dummy model: class TestBaseImage(BaseImage): pass All it does is to inherit from an abstract BaseImage model. Then in tests I create instances of that dummy model to test it. The problem is that it doesn't

Remove app (and associated database tables) in Django 1.7

不羁的心 提交于 2019-12-04 11:08:17
问题 Is it possible to use Django 1.7 migrations to completely remove/uninstall an app and all its traces (mainly, all its database tables)? If not, what is the appropriate way of doing this in Django 1.7? 回答1: python manage.py migrate <app> zero 来源: https://stackoverflow.com/questions/31892027/remove-app-and-associated-database-tables-in-django-1-7