django-1.7

add help text to a read only field in django admin view

僤鯓⒐⒋嵵緔 提交于 2019-12-10 21:07:14
问题 Below is my admin view: @admin.register(AuditStashAwsMasterPolicies) class AuditPoliciesAdmin(reversion.VersionAdmin): exclude = ['source_policy_path', 'source_state', 'target_state'] readonly_fields = ['comparison_date', 'source', 'source_policy_name', 'target', 'target_policy_name', 'target_policy_path', 'policy_difference'] def policy_difference(self, instance): return drift.compare_two_policies(instance.source, instance.source_policy_name, instance.source_policy_path, instance.target,

Django - why can't I access dynamically-generated attributes in classes in my models.py from admin.py?

不问归期 提交于 2019-12-10 20:27:27
问题 Here is models.py : class Parent(models.Model): id = models.CharField(max_length=14, primary_key=True) json_dump = models.TextField(null=False) def __init__(self, *args, **kwargs): super(Base, self).__init__(*args, **kwargs) setattr(self, 'name', json.loads(self.json_dump)['name']) class Meta: abstract = True class Child(Parent): magnitude = models.IntegerField() In my admin.py I would like to configure the admin for Child to have the name attribute displayed, so I have the following: class

Django 1.7: serve a pdf -file (UnicodeDecodeError)

倖福魔咒の 提交于 2019-12-10 15:58:05
问题 I'm trying to serve a PDF file with django 1.7, and this is basically the code that "should" work... it certainly works if I change the content_type to 'text' and download a .tex file with it, but when I try it with a binary file, I get "UnicodeDecodeError at /path/to/file/filename.pdf 'utf-8' codec can't decode byte 0xd0 in position 10: invalid continuation byte" def download(request, file_name): file = open('path/to/file/{}'.format(file_name), 'r') response = HttpResponse(file, content_type

How to fake migrations for not to create a specific existing intermediary table

99封情书 提交于 2019-12-10 14:48:23
问题 I have following models class VucutBolgesi(models.Model): site = models.ForeignKey(Site) bolge = models.CharField(verbose_name="Bölge", max_length=75) hareketler = models.ManyToManyField("Hareket", verbose_name="Hareketler", null=True, blank=True, help_text="Bölgeyi çalıştıran hareketler") class Hareket(models.Model): site = models.ForeignKey(Site) hareket = models.CharField(verbose_name="Hareket", max_length=75 ) bolgeler = models.ManyToManyField(VucutBolgesi, verbose_name="Çalıştırdığı

Migration error with Django 1.7.1

家住魔仙堡 提交于 2019-12-10 13:39:26
问题 I'm getting an error when performing a migration after introducing a new app (django-allauth). I'm not sure what else to try in order to fix the error. I've tried a few things but they don't seem to help unfortunately. when running manage.py migrate : File "D:\Python27\Lib\site-packages\django\db\migrations\state.py", line 71, in render raise InvalidBasesError("Cannot resolve bases for %r\nThis can happen if you are inheriting models from an app with migrations (e.g. contrib.auth)\n in an app

Google & Oauthlib - Scope has changed

无人久伴 提交于 2019-12-10 12:49:34
问题 I am using OAuthlib for conducting OAuth flow of Google. It was working well for 4 to 5 months. Suddenly I started getting below error: File "/home/whitesnow-2/Gaurav/Axonator/AxVirtualEnv/local/lib/python2.7/site-packages/oauthlib/oauth2/rfc6749/parameters.py", line 409, in validate_token_parameters raise w Warning: Scope has changed from "https://www.googleapis.com/auth/calendar https://www.googleapis.com/auth/docs https://www.googleapis.com/auth/spreadsheets https://www.googleapis.com/auth

How to solve the ImportError: cannot import name simplejson in Django

一曲冷凌霜 提交于 2019-12-09 14:49:27
问题 I'm trying to build a realtime chat app in Django(1.7.1). It seems that I needed to install Redis and ishout.js. So I installed them by following the instructions. After making the project in Django, I put 'drealtime' under the INSTALLED_APPS, and put: 'drealtime.middleware.iShoutCookieMiddleware' right above : 'django.contrib.sessions.middleware.SessionMiddleware' under the MIDDLEWARE_CLASSES as it was saying. And I put the command like python manage.py startapp example but still I have this

How to combine select_related() and value()? (2016)

喜你入骨 提交于 2019-12-09 02:31:20
问题 I am asking this question again (it was asked back in 2009), We know there is a values() method of QuerySet, when there is a foreignkey (author, for example), it result like: [{ 'author_id':3, ... }, ...] I want a result like: [{ 'author':{'name':'dave',...}, ... }, ...] Has something changed in the newer versions of Django? I want to convert the query set into a combination of lists and dictionnaries, is it possible? I will then take this object and place it into a bigger object to serialize

Django 1.7 makemigrations renaming tables to None

烈酒焚心 提交于 2019-12-08 21:06:29
问题 I had to move a few models from one app to another, and I followed the instructions on this answer https://stackoverflow.com/a/26472482/188614. Basically I used the CreateModel migrations generated by python manage.py makemigrations , wrapped them inside state_operations , and added the 'db_table' meta option with the old table's name. Everything works fine, the models on the new_app are corretly using the old tables. But if I run python manage.py makemigrations new_app it creates an

Django translations of third party apps

旧时模样 提交于 2019-12-07 12:18:28
问题 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