python - django - invalid literal for int() with base 10 in django Admin | Primary Key CharField -


i'm trying figure out simple (but weird) problem. need modelb have foreign key reference modela (with charfield pk), so:

class modela(models.model):     name = models.charfield(primary_key=true)     tags = taggablemanager()  class modelb(models.model):     model_a = models.foreignkey(modela) 

my code seems understand in runtime , can create modela/modelb objects no problem.

however, when try manually add/delete model objects in django admin, kind of value exception.

exception value: invalid literal int() base 10: 

i know has trying interpret key charfield int() id, why djangowebsite/admin not know how deal these relationships?

update: full stack trace:

environment:   request method: post request url: http://127.0.0.1:5000/admin/src/ratedmodel/add/  django version: 1.7.7 python version: 3.4.3 installed applications: ('src',  'django.contrib.admin',  'django.contrib.auth',  'django.contrib.contenttypes',  'django.contrib.sessions',  'django.contrib.messages',  'django.contrib.staticfiles',  'taggit') installed middleware: ('django.contrib.sessions.middleware.sessionmiddleware',  'django.middleware.common.commonmiddleware',  'django.middleware.csrf.csrfviewmiddleware',  'django.contrib.auth.middleware.authenticationmiddleware',  'django.contrib.auth.middleware.sessionauthenticationmiddleware',  'django.contrib.messages.middleware.messagemiddleware',  'django.middleware.clickjacking.xframeoptionsmiddleware')   traceback: file "c:\venv\lib\site-packages\django\core\handlers\base.py" in get_response   111.                     response = wrapped_callback(request, *callback_args, **callback_kwargs) file "c:\venv\lib\site-packages\django\contrib\admin\options.py" in wrapper   583.                 return self.admin_site.admin_view(view)(*args, **kwargs) file "c:\venv\lib\site-packages\django\utils\decorators.py" in _wrapped_view   105.                     response = view_func(request, *args, **kwargs) file "c:\venv\lib\site-packages\django\views\decorators\cache.py" in _wrapped_view_func   52.         response = view_func(request, *args, **kwargs) file "c:\venv\lib\site-packages\django\contrib\admin\sites.py" in inner   206.             return view(request, *args, **kwargs) file "c:\venv\lib\site-packages\django\contrib\admin\options.py" in add_view   1453.         return self.changeform_view(request, none, form_url, extra_context) file "c:\venv\lib\site-packages\django\utils\decorators.py" in _wrapper   29.             return bound_func(*args, **kwargs) file "c:\venv\lib\site-packages\django\utils\decorators.py" in _wrapped_view   105.                     response = view_func(request, *args, **kwargs) file "c:\venv\lib\site-packages\django\utils\decorators.py" in bound_func   25.                 return func.__get__(self, type(self))(*args2, **kwargs2) file "c:\venv\lib\site-packages\django\db\transaction.py" in inner   394.                 return func(*args, **kwargs) file "c:\venv\lib\site-packages\django\contrib\admin\options.py" in changeform_view   1405.                 self.save_related(request, form, formsets, not add) file "c:\venv\lib\site-packages\django\contrib\admin\options.py" in save_related   1067.         form.save_m2m() file "c:\venv\lib\site-packages\django\forms\models.py" in save_m2m   100.                 f.save_form_data(instance, cleaned_data[f.name]) file "c:\venv\lib\site-packages\taggit\managers.py" in save_form_data   373.         getattr(instance, self.name).set(*value) file "c:\venv\lib\site-packages\taggit\utils.py" in inner   136.         return func(self, *args, **kwargs) file "c:\venv\lib\site-packages\taggit\managers.py" in set   184.         self.clear() file "c:\venv\lib\site-packages\taggit\utils.py" in inner   136.         return func(self, *args, **kwargs) file "c:\venv\lib\site-packages\taggit\managers.py" in clear   194.         self.through.objects.filter(**self._lookup_kwargs()).delete() file "c:\venv\lib\site-packages\django\db\models\manager.py" in manager_method   92.                 return getattr(self.get_queryset(), name)(*args, **kwargs) file "c:\venv\lib\site-packages\django\db\models\query.py" in filter   691.         return self._filter_or_exclude(false, *args, **kwargs) file "c:\venv\lib\site-packages\django\db\models\query.py" in _filter_or_exclude   709.             clone.query.add_q(q(*args, **kwargs)) file "c:\venv\lib\site-packages\django\db\models\sql\query.py" in add_q   1331.         clause, require_inner = self._add_q(where_part, self.used_aliases) file "c:\venv\lib\site-packages\django\db\models\sql\query.py" in _add_q   1358.                     current_negated=current_negated, connector=connector) file "c:\venv\lib\site-packages\django\db\models\sql\query.py" in build_filter   1230.             condition = self.build_lookup(lookups, col, value) file "c:\venv\lib\site-packages\django\db\models\sql\query.py" in build_lookup   1138.                     return final_lookup(lhs, rhs) file "c:\venv\lib\site-packages\django\db\models\lookups.py" in __init__   82.         self.rhs = self.get_prep_lookup() file "c:\venv\lib\site-packages\django\db\models\lookups.py" in get_prep_lookup   85.         return self.lhs.output_field.get_prep_lookup(self.lookup_name, self.rhs) file "c:\venv\lib\site-packages\django\db\models\fields\__init__.py" in get_prep_lookup   1607.         return super(integerfield, self).get_prep_lookup(lookup_type, value) file "c:\venv\lib\site-packages\django\db\models\fields\__init__.py" in get_prep_lookup   646.             return self.get_prep_value(value) file "c:\venv\lib\site-packages\django\db\models\fields\__init__.py" in get_prep_value   1601.         return int(value)  exception type: valueerror @ /admin/src/ratedmodel/add/ exception value: invalid literal int() base 10: 'modelaname' 

update:

i have strong feeling has taggable manager utility i'm trying use. suspect defaults thinking modela has int() pk. still investigating.

my mistake. seems because doesn't fact i'm using name primary key. changed name has unique=true rule , fixed issue.


Comments

Popular posts from this blog

facebook - android ACTION_SEND to share with specific application only -

python - Creating a new virtualenv gives a permissions error -

javascript - cocos2d-js draw circle not instantly -