attributeerror

Django nested inlines not working?

耗尽温柔 提交于 2020-01-16 04:48:23
问题 I've installed django-nested-inline but I have problems. Here's my code: from django.contrib import admin from nested_inline.admin import NestedStackedInline, NestedModelAdmin from .models import Positive, Negative, Option, Question class PositiveInline(NestedStackedInline): model = Positive class NegativeInline(NestedStackedInline): model = Negative class OptionInline(NestedStackedInline): model = Option inlines = [PositiveInline, NegativeInline,] class QuestionAdmin(NestedModelAdmin):

Model.ManyToManyField.all() gives AttributeError: 'ManyToManyDescriptor' object has no attribute 'all'

北战南征 提交于 2020-01-15 11:49:26
问题 I'm using Django 2.0.2, Python 3.6.4 and PyCharm 2017.3.3 Models: (in models.py) class Position(models.Model): title = models.CharField(max_length=50) gang = models.ForeignKey(Gang, on_delete=models.CASCADE) description = models.TextField(max_length=20000) def __str__(self): return str(self.title) + ', ' + str(self.gang) class Application(models.Model): positions = models.ManyToManyField(Position) applicant = models.ForeignKey(User, on_delete=models.CASCADE) class Ranking(models.Model):

Matplotlib set_major_formatter AttributeError

左心房为你撑大大i 提交于 2020-01-15 05:33:07
问题 I'm trying to format the yaxis on a matplotlib graph using set_major_formatter. The plot is generated correctly, but the ax.yaxis.set_major_formatter() throws a couple of weird errors. The formatter: def mjrFormatter(x): return "{0:.0f}%".format(x * 100) The code that uses the formatter: ... ax.yaxis.set_major_formatter(mjrFormatter) ... Error: --------------------------------------------------------------------------- AttributeError Traceback (most recent call last) <ipython-input-108

'ReverseManyToOneDescriptor' object has no attribute 'latest'

你。 提交于 2020-01-14 18:52:52
问题 I have received this error when trying to run a function. This is my first django/python project so I am not experienced in this. I have searched for this error but not found anything similar. def getpriority(chunks): p = 0 for chunk in chunks: a = chunk.result_set.all() l = a.latest() if pytz.utc.localize(datetime.now()) - l.timestamp > datetime.timedelta(days=3): x = getresult(chunk) print(x) I am trying to assign priorities to my Chunk model so I can select the Chunk with the highest

'ReverseManyToOneDescriptor' object has no attribute 'latest'

為{幸葍}努か 提交于 2020-01-14 18:50:50
问题 I have received this error when trying to run a function. This is my first django/python project so I am not experienced in this. I have searched for this error but not found anything similar. def getpriority(chunks): p = 0 for chunk in chunks: a = chunk.result_set.all() l = a.latest() if pytz.utc.localize(datetime.now()) - l.timestamp > datetime.timedelta(days=3): x = getresult(chunk) print(x) I am trying to assign priorities to my Chunk model so I can select the Chunk with the highest

Django error 'unicode' object has no attribute 'objects'

不打扰是莪最后的温柔 提交于 2020-01-14 18:46:27
问题 I'm writing my first django app from https://docs.djangoproject.com/en/dev/intro/tutorial01/ and i'm experiencing 2 problems. My Models.py are from django.db import models class Poll(models.Model): question = models.CharField(max_length=200) pub_date = models.DateTimeField('date published') def _unicode_(self): return self.question self.question class Choice(models.Model): poll = models.ForeignKey(Poll) choice_text = models.CharField(max_length=200) votes = models.IntegerField(default=0) def

Django error 'unicode' object has no attribute 'objects'

一笑奈何 提交于 2020-01-14 18:46:13
问题 I'm writing my first django app from https://docs.djangoproject.com/en/dev/intro/tutorial01/ and i'm experiencing 2 problems. My Models.py are from django.db import models class Poll(models.Model): question = models.CharField(max_length=200) pub_date = models.DateTimeField('date published') def _unicode_(self): return self.question self.question class Choice(models.Model): poll = models.ForeignKey(Poll) choice_text = models.CharField(max_length=200) votes = models.IntegerField(default=0) def

how to count specific words from a pandas Series?

会有一股神秘感。 提交于 2020-01-14 14:47:09
问题 I am trying to count the number of keywords from a pandas DataFrame as such: df = pd.read_csv('amazon_baby.csv') selected_words = ['awesome', 'great', 'fantastic', 'amazing', 'love', 'horrible', 'bad', 'terrible', 'awful', 'wow', 'hate'] The selected_words have to be counted from the Series: df['review'] i have tried def word_counter(sent): a={} for word in selected_words: a[word] = sent.count(word) return a and then df['totalwords'] = df.review.str.split() df['word_count'] = df.totalwords

AttributeError when importing modules in Python 3

喜欢而已 提交于 2020-01-14 04:40:51
问题 I am trying to write a script that makes use of the json and requests modules. Before I wrote the script, I was playing around with commands on the interactive shell, and since creating an actual file for my code, everything has somehow broken. The first time I ran the code, a pycache folder appeared in the folder and I think that is somehow breaking everthing. The code, when run line by line in the shell, no longer works either with the presence of this pycache folder. My code is as follows:

Error in py2app application

℡╲_俬逩灬. 提交于 2020-01-07 07:55:48
问题 (OSX = Mountain lion) My app in /dist throws the error: Last login: Wed Aug 28 11:21:29 on ttys001 -MacBook-Pro:~ $ /Users/Desktop/dist/abc.app/Contents/MacOS/abc ; exit; Traceback (most recent call last): File "/usr/local/lib/python2.7/site-packages/py2app/apptemplate/lib/site.py", line 20, in <module> import os File "os.pyc", line 398, in <module> File "UserDict.pyc", line 83, in <module> File "_abcoll.pyc", line 11, in <module> File "/Users/Virendra/Desktop/dist/abc.app/Contents/Resources