Re: CPU usage by workers

2017-05-25 Thread qnub
For those who have same CPU usage issue — my mistake was in isage 
RedisLocalChannelLayer in combo with delay server. 

Looks like many delayed messages just hangs on nodes. I've thought it 
should be executed on same node, but seems partially it was consumed, but 
partially hangs.
Then i've tried to run delay worker on single node and hope it'll consume 
delayed messages from all other nodes, but it's not work too.
Then i've switched this node from RedisLocalChannelLayer to 
RedisChannelLayer and seems like all nodes start to ignore this settings 
and consume all existed messages. Also CPU usage lowered to the 0-1%

So i've just switch all nodes to RedisChannelLayer.

On Monday, May 15, 2017 at 8:37:59 PM UTC+6, qnub wrote:
>
> Thanks for suggestions but i have found nothing suspicious. 
>
> But i've installed pyinotify and switch to running workers in separate 
> processes manually instead of using --threads option.
> Not sure which of this actions helps more but now CPU usage floating 
> around 15-25%
>
> On Wednesday, May 10, 2017 at 5:58:38 PM UTC+6, Melvyn Sopacua wrote:
>>
>> On Tuesday 09 May 2017 23:21:23 qnub wrote:
>>
>>  
>>
>> > Also it's may be my fault somewhere (and i pretty sure it is). But i
>>
>> > not sure where to start my investigation.
>>
>>  
>>
>> I would start with strace 
>>  - a common 
>> cause for this is expecting a resource that does not exist and keep trying. 
>> A filename or network address / port number can be that candle in the dark.
>>
>>  
>>
>> -- 
>>
>> Melvyn Sopacua
>>
>

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/4b845943-ec1d-4749-bb9b-5c5fe6a3bc10%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


null value in column violates not-null constraint

2017-05-25 Thread Ismail Sarenkapic
Hi, I'm trying to create a digital marketplace site where users will be 
able to register and submit their products.
I created the Product model and connected it with User with foreign 
key.Everything seems  to be alright, but when I submit my product i get the 
following error:

null value in column violates not-null constraint
 it looks like relation between product and user is not properly 
configured(regardless of my mixin that is suppose to handle it)
__
note that I'm using:

database:postgresql

allauth(for user registration)
__


models.py

from django.conf import settings
from django.db import models
from django.db.models.signals import pre_save, post_save
from django.core.urlresolvers import reverse
from django.utils.text import slugify
# Create your models here.



class Product(models.Model):
   seller = models.ForeignKey(settings.AUTH_USER_MODEL)
   #user = models.OneToOneField(settings.AUTH_USER_MODEL)
   # user = models.ForeignKey(settings.AUTH_USER_MODEL)
   # managers = models.ManyToManyField(settings.AUTH_USER_MODEL, 
related_name="managers_products", blank=True)
   title = models.CharField(max_length=30) 
#owiuerpoajsdlfkjasd;flkiu1p3o4u134123 ewjfa;sd
   slug = models.SlugField(blank=True, unique=True)
   description = models.TextField()
   price = models.DecimalField(max_digits=100, decimal_places=2, default=9.99, 
null=True,) #100.00


   def __unicode__(self): #def __unicode__(self):
  return self.title

___
views.py


from django.views import View
from django.views.generic import (
CreateView,
)

from .forms import ProductModelForm
from .mixins import FormUserNeededMixin
# Create your views here.


class ProductCreateView(FormUserNeededMixin, CreateView):
form_class = ProductModelForm
template_name = 'create_view.html'

___
forms.py

from django import forms

from django.utils.text import slugify

from .models import Product


class ProductModelForm(forms.ModelForm):
   class Meta:
  model = Product
  fields = [
 "title",
 "description",
 "price",
  ]


mixins.py

from django import forms
from django.forms.utils import ErrorList

class FormUserNeededMixin(object):

 def form_valid(self, form):
if self.request.user.is_authenticated():
form.instance.user = self.request.user
return super(FormUserNeededMixin, self).form_valid(form)
else:
form._errors[forms.forms.NON_FIELD_ERRORS] = ErrorList(["User must 
be logged in to continue."])
return self.form_invalid(form)







-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/0d2d44eb-a2df-4f00-8d60-3f163ed72c9b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Connecting django to postgresql database

2017-05-25 Thread Njogu
I have been trying to connect my django project to postrgesql database, i 
have one the configurations to it perfectly like this;


ALLOWED_HOSTS = ['localhost', '127.0.0.1']

DATABASES = {
'default': {
'ENGINE' : 'django.db.backends.postgresql_psycopg2',
'NAME'  : 'firstdjangoproject',
'USER'  : 'djangouser',
'PASSWORD' : 'django254',
'HOST'  : '127.0.0.1',
'PORT'  : '5432',
}

however when i run the command *'python manage.py migrate'* it does not 
identify the word migrate, and when i run the command '*python manage.py 
syncdb*' i get the following error;

Traceback (most recent call last):
  File "manage.py", line 10, in 
execute_from_command_line(sys.argv)
  File 
"/usr/local/lib/python2.7/dist-packages/Django-1.11.1-py2.7.egg/django/core/management/__init__.py",
 
line 363, in execute_from_command_line
utility.execute()
  File 
"/usr/local/lib/python2.7/dist-packages/Django-1.11.1-py2.7.egg/django/core/management/__init__.py",
 
line 337, in execute
django.setup()
  File 
"/usr/local/lib/python2.7/dist-packages/Django-1.11.1-py2.7.egg/django/__init__.py",
 
line 27, in setup
apps.populate(settings.INSTALLED_APPS)
  File 
"/usr/local/lib/python2.7/dist-packages/Django-1.11.1-py2.7.egg/django/apps/registry.py",
 
line 108, in populate
app_config.import_models()
  File 
"/usr/local/lib/python2.7/dist-packages/Django-1.11.1-py2.7.egg/django/apps/config.py",
 
line 202, in import_models
self.models_module = import_module(models_module_name)
  File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
  File 
"/usr/local/lib/python2.7/dist-packages/Django-1.11.1-py2.7.egg/django/contrib/auth/models.py",
 
line 4, in 
from django.contrib.auth.base_user import AbstractBaseUser, 
BaseUserManager
  File 
"/usr/local/lib/python2.7/dist-packages/Django-1.11.1-py2.7.egg/django/contrib/auth/base_user.py",
 
line 52, in 
class AbstractBaseUser(models.Model):
  File 
"/usr/local/lib/python2.7/dist-packages/Django-1.11.1-py2.7.egg/django/db/models/base.py",
 
line 124, in __new__
new_class.add_to_class('_meta', Options(meta, app_label))
  File 
"/usr/local/lib/python2.7/dist-packages/Django-1.11.1-py2.7.egg/django/db/models/base.py",
 
line 330, in add_to_class
value.contribute_to_class(cls, name)
  File 
"/usr/local/lib/python2.7/dist-packages/Django-1.11.1-py2.7.egg/django/db/models/options.py",
 
line 214, in contribute_to_class
self.db_table = truncate_name(self.db_table, 
connection.ops.max_name_length())
  File 
"/usr/local/lib/python2.7/dist-packages/Django-1.11.1-py2.7.egg/django/db/__init__.py",
 
line 33, in __getattr__
return getattr(connections[DEFAULT_DB_ALIAS], item)
  File 
"/usr/local/lib/python2.7/dist-packages/Django-1.11.1-py2.7.egg/django/db/utils.py",
 
line 211, in __getitem__
backend = load_backend(db['ENGINE'])
  File 
"/usr/local/lib/python2.7/dist-packages/Django-1.11.1-py2.7.egg/django/db/utils.py",
 
line 115, in load_backend
return import_module('%s.base' % backend_name)
  File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
  File 
"/usr/local/lib/python2.7/dist-packages/Django-1.11.1-py2.7.egg/django/db/backends/postgresql/base.py",
 
line 36, in 
raise ImproperlyConfigured("psycopg2_version 2.5.4 or newer is 
required; you have %s" % psycopg2.__version__)
django.core.exceptions.ImproperlyConfigured: psycopg2_version 2.5.4 or 
newer is required; you have 2.4.5 (dt dec mx pq3 ext)

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/a9e7f2c4-966d-45fe-aebc-681bacba6b74%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Connecting django to postgresql database

2017-05-25 Thread Antonis Christofides
Hello,

1) You say that "it does not identify the word migrate". Could you please show
us the exact error message?

2) The message you are getting, "psycopg2_version 2.5.4 or newer is required;
you have 2.4.5" seems perfectly clear. Could you elaborate on why you have
trouble correcting it?

Regards,

A.

Antonis Christofides
http://djangodeployment.com

On 2017-05-25 09:44, Njogu wrote:
> I have been trying to connect my django project to postrgesql database, i have
> one the configurations to it perfectly like this;
>
>
> ALLOWED_HOSTS = ['localhost', '127.0.0.1']
>
> DATABASES = {
> 'default': {
> 'ENGINE' : 'django.db.backends.postgresql_psycopg2',
> 'NAME'  : 'firstdjangoproject',
> 'USER'  : 'djangouser',
> 'PASSWORD' : 'django254',
> 'HOST'  : '127.0.0.1',
> 'PORT'  : '5432',
> }
>
> however when i run the command *'python manage.py migrate'* it does not
> identify the word migrate, and when i run the command '*python manage.py
> syncdb*' i get the following error;
>
> Traceback (most recent call last):
>   File "manage.py", line 10, in 
> execute_from_command_line(sys.argv)
>   File
> "/usr/local/lib/python2.7/dist-packages/Django-1.11.1-py2.7.egg/django/core/management/__init__.py",
> line 363, in execute_from_command_line
> utility.execute()
>   File
> "/usr/local/lib/python2.7/dist-packages/Django-1.11.1-py2.7.egg/django/core/management/__init__.py",
> line 337, in execute
> django.setup()
>   File
> "/usr/local/lib/python2.7/dist-packages/Django-1.11.1-py2.7.egg/django/__init__.py",
> line 27, in setup
> apps.populate(settings.INSTALLED_APPS)
>   File
> "/usr/local/lib/python2.7/dist-packages/Django-1.11.1-py2.7.egg/django/apps/registry.py",
> line 108, in populate
> app_config.import_models()
>   File
> "/usr/local/lib/python2.7/dist-packages/Django-1.11.1-py2.7.egg/django/apps/config.py",
> line 202, in import_models
> self.models_module = import_module(models_module_name)
>   File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
> __import__(name)
>   File
> "/usr/local/lib/python2.7/dist-packages/Django-1.11.1-py2.7.egg/django/contrib/auth/models.py",
> line 4, in 
> from django.contrib.auth.base_user import AbstractBaseUser, 
> BaseUserManager
>   File
> "/usr/local/lib/python2.7/dist-packages/Django-1.11.1-py2.7.egg/django/contrib/auth/base_user.py",
> line 52, in 
> class AbstractBaseUser(models.Model):
>   File
> "/usr/local/lib/python2.7/dist-packages/Django-1.11.1-py2.7.egg/django/db/models/base.py",
> line 124, in __new__
> new_class.add_to_class('_meta', Options(meta, app_label))
>   File
> "/usr/local/lib/python2.7/dist-packages/Django-1.11.1-py2.7.egg/django/db/models/base.py",
> line 330, in add_to_class
> value.contribute_to_class(cls, name)
>   File
> "/usr/local/lib/python2.7/dist-packages/Django-1.11.1-py2.7.egg/django/db/models/options.py",
> line 214, in contribute_to_class
> self.db_table = truncate_name(self.db_table, 
> connection.ops.max_name_length())
>   File
> "/usr/local/lib/python2.7/dist-packages/Django-1.11.1-py2.7.egg/django/db/__init__.py",
> line 33, in __getattr__
> return getattr(connections[DEFAULT_DB_ALIAS], item)
>   File
> "/usr/local/lib/python2.7/dist-packages/Django-1.11.1-py2.7.egg/django/db/utils.py",
> line 211, in __getitem__
> backend = load_backend(db['ENGINE'])
>   File
> "/usr/local/lib/python2.7/dist-packages/Django-1.11.1-py2.7.egg/django/db/utils.py",
> line 115, in load_backend
> return import_module('%s.base' % backend_name)
>   File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
> __import__(name)
>   File
> "/usr/local/lib/python2.7/dist-packages/Django-1.11.1-py2.7.egg/django/db/backends/postgresql/base.py",
> line 36, in 
> raise ImproperlyConfigured("psycopg2_version 2.5.4 or newer is required;
> you have %s" % psycopg2.__version__)
> django.core.exceptions.ImproperlyConfigured: psycopg2_version 2.5.4 or newer
> is required; you have 2.4.5 (dt dec mx pq3 ext)
>
> -- 
> 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 https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/a9e7f2c4-966d-45fe-aebc-681bacba6b74%40googlegroups.com
> .
> 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

Re: Connecting django to postgresql database

2017-05-25 Thread Daniel Roseman
On Thursday, 25 May 2017 12:48:32 UTC+1, Njogu wrote:
>
>
> however when i run the command *'python manage.py migrate'* it does not 
> identify the word migrate, and when i run the command '*python manage.py 
> syncdb*' i get the following error;
>

syncdb has not existed in Django since version 1.8. There is no way you can 
be running this command in version 1.11.
--
DR.

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/44af8c18-85ab-40ff-833e-3c0891a38386%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Custom Model Manager

2017-05-25 Thread 'dtdave' via Django users
I apologise if this is a simple question but I am still somewhat new to 
Dajngo.
I have the following models:

Jobs Model
Candidates Model
Applications Model

The jobs model has a manager on it as follows:
class ExpiredManager(models.Manager):
def get_queryset(self):
return super(ExpiredManager, self).get_queryset() \
 .filter(expiry_date__gt=datetime.now()).order_by('start_date')

And to make sure only unexpired items are listed on the web page my 
managers are listed as follows:
objects = ExpiredManager()
with_expired_objects = models.Manager()

Within my admin I have the following:
def get_queryset(self, request):
"""To return all jobs in admin including those that are expired"""
qs = self.model.with_expired_objects.get_queryset()
ordering = self.get_ordering(request)
if ordering:
qs = qs.order_by(*ordering)
return qs
At this stage evrything works exactly as I want it to with all jobs being 
shown in the admin and only unexpired jobs on the web page.

My candidates model has the following field:
jobs = models.ManyToManyField('jobs.Job', 
through="applications.Application")

My application model has fields for candidate and jobs.
My problem is that once the job expires it is being dropped from both the 
candidates and the applications as obviously the expired items manager is 
the default.
Any help on how to correct this would be appreciated.
Many thanks


-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/a9349301-03db-4793-856b-b62836854de9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Custom Model Manager

2017-05-25 Thread Melvyn Sopacua
On Thursday 25 May 2017 08:37:32 'dtdave' via Django users wrote:

> My application model has fields for candidate and jobs.
> My problem is that once the job expires it is being dropped from both
> the candidates and the applications as obviously the expired items
> manager is the default.
> Any help on how to correct this would be appreciated.

The trick to Django is knowing where to find the relevant 
documentation bit[1].
-- 
Melvyn Sopacua


[1] https://docs.djangoproject.com/en/1.11/ref/models/options/#base-manager-name

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/2567353.Uvk92CTyiI%40devstation.
For more options, visit https://groups.google.com/d/optout.


Re: Custom Model Manager

2017-05-25 Thread 'David Turner' via Django users
That would be fine if I was using 1.10 but this is a legacy system using
1.9. This will be upgraded in the foreseeable future to 1.11

Thanks

On 25 May 2017 at 17:01, Melvyn Sopacua  wrote:

> On Thursday 25 May 2017 08:37:32 'dtdave' via Django users wrote:
>
>
>
> > My application model has fields for candidate and jobs.
>
> > My problem is that once the job expires it is being dropped from both
>
> > the candidates and the applications as obviously the expired items
>
> > manager is the default.
>
> > Any help on how to correct this would be appreciated.
>
>
>
> The trick to Django is knowing where to find the relevant documentation
> bit
> 
> .
>
> --
>
> Melvyn Sopacua
>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "Django users" group.
> To unsubscribe from this topic, visit https://groups.google.com/d/
> topic/django-users/AjQXrIrkEjw/unsubscribe.
> To unsubscribe from this group and all its topics, 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 https://groups.google.com/group/django-users.
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/django-users/2567353.Uvk92CTyiI%40devstation
> 
> .
>
> 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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CALwQ%2B-tqHEyRAKQ0F_JwOahhTHhauRLV7w0GMM25TwUOMfzSDg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: null value in column violates not-null constraint

2017-05-25 Thread Melvyn Sopacua
On Thursday 25 May 2017 04:19:56 Ismail Sarenkapic wrote:
> Hi, I'm trying to create a digital marketplace site where users will
> be able to register and submit their products.
> I created the Product model and connected it with User with foreign
> key.Everything seems  to be alright, but when I submit my product i
> get the following error:
> 
> null value in column violates not-null constraint
>  it looks like relation between product and user is not properly
> configured(regardless of my mixin that is suppose to handle it)

> class Product(models.Model):
>seller = models.ForeignKey(settings.AUTH_USER_MODEL)
>#user = models.OneToOneField(settings.AUTH_USER_MODEL)
># user = models.ForeignKey(settings.AUTH_USER_MODEL)
># managers = models.ManyToManyField(settings.AUTH_USER_MODEL,
> related_name="managers_products", blank=True) title =
> models.CharField(max_length=30)
> #owiuerpoajsdlfkjasd;flkiu1p3o4u134123 ewjfa;sd slug =
> models.SlugField(blank=True, unique=True)
>description = models.TextField()
>price = models.DecimalField(max_digits=100, decimal_places=2,
> default=9.99, null=True,) #100.00


> class ProductModelForm(forms.ModelForm):
>class Meta:
>   model = Product
>   fields = [
>  "title",
>  "description",
>  "price",
>   ]

seller is not in the model form and FormUserNeededMixin doesn't change that. 
The user field 
is commented out in your model so this error and the quoted code are not in 
sync.

But it could also be the slug. Without more of the error message it's hard to 
tell.
-- 
Melvyn Sopacua

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/12993399.QfppCMPifr%40devstation.
For more options, visit https://groups.google.com/d/optout.


Re: null value in column violates not-null constraint

2017-05-25 Thread Muhammad M
Ismail,

You don't seem to be handling the value for Product.slug anywhere, either
in the model or the view.

You can fix the slug issue by overriding the Product model's save () method
like this:

def save (self, *args, **kwargs):
 if not self.slug:
self.slug = slugify(self.title)
super(Product, self).save (*args, **kwargs)

This way, you can automatically generate the value of the slug field when a
valid form is submitted.

If you are still having problems, please, do let us know.

All the best.

Sincerely,
Muhammad

On May 25, 2017 7:20 AM, "Ismail Sarenkapic"  wrote:

Hi, I'm trying to create a digital marketplace site where users will be
able to register and submit their products.
I created the Product model and connected it with User with foreign
key.Everything seems  to be alright, but when I submit my product i get the
following error:

null value in column violates not-null constraint
 it looks like relation between product and user is not properly
configured(regardless of my mixin that is suppose to handle it)

__
note that I'm using:

database:postgresql

allauth(for user registration)

__


models.py

from django.conf import settings
from django.db import models
from django.db.models.signals import pre_save, post_save
from django.core.urlresolvers import reverse
from django.utils.text import slugify
# Create your models here.



class Product(models.Model):
   seller = models.ForeignKey(settings.AUTH_USER_MODEL)
   #user = models.OneToOneField(settings.AUTH_USER_MODEL)
   # user = models.ForeignKey(settings.AUTH_USER_MODEL)
   # managers = models.ManyToManyField(settings.AUTH_USER_MODEL,
related_name="managers_products", blank=True)
   title = models.CharField(max_length=30)
#owiuerpoajsdlfkjasd;flkiu1p3o4u134123 ewjfa;sd
   slug = models.SlugField(blank=True, unique=True)
   description = models.TextField()
   price = models.DecimalField(max_digits=100, decimal_places=2,
default=9.99, null=True,) #100.00


   def __unicode__(self): #def __unicode__(self):
  return self.title

___
views.py


from django.views import View
from django.views.generic import (
CreateView,
)

from .forms import ProductModelForm
from .mixins import FormUserNeededMixin
# Create your views here.


class ProductCreateView(FormUserNeededMixin, CreateView):
form_class = ProductModelForm
template_name = 'create_view.html'

___
forms.py

from django import forms

from django.utils.text import slugify

from .models import Product


class ProductModelForm(forms.ModelForm):
   class Meta:
  model = Product
  fields = [
 "title",
 "description",
 "price",
  ]


mixins.py

from django import forms
from django.forms.utils import ErrorList

class FormUserNeededMixin(object):

 def form_valid(self, form):
if self.request.user.is_authenticated():
form.instance.user = self.request.user
return super(FormUserNeededMixin, self).form_valid(form)
else:
form._errors[forms.forms.NON_FIELD_ERRORS] =
ErrorList(["User must be logged in to continue."])
return self.form_invalid(form)







-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/
msgid/django-users/0d2d44eb-a2df-4f00-8d60-3f163ed72c9b%40googlegroups.com

.
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAJOFuZwG1w%2B9-c3xP9aX3D5ggNv6FymU%3DG7nBOaHSjCgGwGJ1A%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: saving data from both a model and a derived model

2017-05-25 Thread James Schneider
On Wed, May 24, 2017 at 11:03 AM, Jim Anderson 
wrote:

> Hi James,
>
> I'm attaching the stacktrace as you requested.
>
>
Thanks. It is quite telling:

  File 
"/home/jja/testenv3.5/lib/python3.5/site-packages/django/db/backends/sqlite3/base.py",
line 337, in execute
return Database.Cursor.execute(self, query, params)
django.db.utils.IntegrityError: UNIQUE constraint failed: siggy_stemplate.name


The object you are working with is having a 'name' clash with another
object of the same type. You've set the 'name' field to be unique, so
you'll need to ensure that each object has a unique value for the 'name'
field. Either check for uniqueness before assigning it, or attempt to save,
catch this exception, and generate a more unique value as needed, rinse and
repeat as necessary.

-James

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CA%2Be%2BciXe1xbw0F9su1RsVbbN_jeGhFynzLjGExL%3DiSAwT45svw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Custom Model Manager

2017-05-25 Thread 'David Turner' via Django users
Apologies I was being really a bit too clever. I just need to put the
deault manager first in my model and then use my custom manager in my view
queryset and everything is fine.

On 25 May 2017 at 18:01, David Turner  wrote:

> That would be fine if I was using 1.10 but this is a legacy system using
> 1.9. This will be upgraded in the foreseeable future to 1.11
>
> Thanks
>
> On 25 May 2017 at 17:01, Melvyn Sopacua  wrote:
>
>> On Thursday 25 May 2017 08:37:32 'dtdave' via Django users wrote:
>>
>>
>>
>> > My application model has fields for candidate and jobs.
>>
>> > My problem is that once the job expires it is being dropped from both
>>
>> > the candidates and the applications as obviously the expired items
>>
>> > manager is the default.
>>
>> > Any help on how to correct this would be appreciated.
>>
>>
>>
>> The trick to Django is knowing where to find the relevant documentation
>> bit
>> 
>> .
>>
>> --
>>
>> Melvyn Sopacua
>>
>> --
>> You received this message because you are subscribed to a topic in the
>> Google Groups "Django users" group.
>> To unsubscribe from this topic, visit https://groups.google.com/d/to
>> pic/django-users/AjQXrIrkEjw/unsubscribe.
>> To unsubscribe from this group and all its topics, 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 https://groups.google.com/group/django-users.
>> To view this discussion on the web visit https://groups.google.com/d/ms
>> gid/django-users/2567353.Uvk92CTyiI%40devstation
>> 
>> .
>>
>> 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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CALwQ%2B-uk91JRYc%3Dd9P%2Bfi5yFnwH%2B3x0bvUZfsBti0GDzmP1Z8w%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Ory editor integration

2017-05-25 Thread Jamesie Pic
Hi all,

I found this new WYSIWYG promising:

https://github.com/ory/editor

Anybody already working on integration of ORY editor with Django ?

Thanks !

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/81fc9809-16a9-4c0d-a3c7-fe359a957c2f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Django 1.11: JSONField loaded as string during migration's RunPython

2017-05-25 Thread hector . urbina
Hello,

We are moving to Django 1.11, but we have some models with JSONField 
fields, which are being used on some custom migration functions (called 
with RunPython). We're getting the following kind of errors:

_ForecastType = apps.get_model('forecast', 'forecasttype')
for forecast_type in _ForecastType.objects.all():
> hours = forecast_type.params['reception_hours']
E TypeError: string indices must be integers

so Django is not properly loading the field during the migration. What 
should we do to fix it?

Thanks very much for any help,
Hector.

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/4d634ed6-e75d-4a7e-aa4c-3c5514e34ac0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: null value in column violates not-null constraint

2017-05-25 Thread Ismail Sarenkapic
Tnx ,
I know that i can manually select the user, but i want it to be 
automatic-with current user to add the product

On Thursday, May 25, 2017 at 7:13:39 PM UTC+2, Melvyn Sopacua wrote:
>
> On Thursday 25 May 2017 04:19:56 Ismail Sarenkapic wrote:
>
> > Hi, I'm trying to create a digital marketplace site where users will
>
> > be able to register and submit their products.
>
> > I created the Product model and connected it with User with foreign
>
> > key.Everything seems to be alright, but when I submit my product i
>
> > get the following error:
>
> > 
>
> > null value in column violates not-null constraint
>
> > it looks like relation between product and user is not properly
>
> > configured(regardless of my mixin that is suppose to handle it)
>
>  
>
> > class Product(models.Model):
>
> > seller = models.ForeignKey(settings.AUTH_USER_MODEL)
>
> > #user = models.OneToOneField(settings.AUTH_USER_MODEL)
>
> > # user = models.ForeignKey(settings.AUTH_USER_MODEL)
>
> > # managers = models.ManyToManyField(settings.AUTH_USER_MODEL,
>
> > related_name="managers_products", blank=True) title =
>
> > models.CharField(max_length=30)
>
> > #owiuerpoajsdlfkjasd;flkiu1p3o4u134123 ewjfa;sd slug =
>
> > models.SlugField(blank=True, unique=True)
>
> > description = models.TextField()
>
> > price = models.DecimalField(max_digits=100, decimal_places=2,
>
> > default=9.99, null=True,) #100.00
>
>  
>
>  
>
> > class ProductModelForm(forms.ModelForm):
>
> > class Meta:
>
> > model = Product
>
> > fields = [
>
> > "title",
>
> > "description",
>
> > "price",
>
> > ]
>
>  
>
> seller is not in the model form and FormUserNeededMixin doesn't change 
> that. The user field is commented out in your model so this error and the 
> quoted code are not in sync.
>
>  
>
> But it could also be the slug. Without more of the error message it's hard 
> to tell.
>
> -- 
>
> Melvyn Sopacua
>

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/ddc8f477-7668-4694-8be8-867494022bf7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: null value in column violates not-null constraint

2017-05-25 Thread Ismail Sarenkapic
Tnx.
The slug is not important here.
The main question is how do I add product  with current user!

On Thursday, May 25, 2017 at 8:00:08 PM UTC+2, Muhammad wrote:
>
> Ismail,
>
> You don't seem to be handling the value for Product.slug anywhere, either 
> in the model or the view. 
>
> You can fix the slug issue by overriding the Product model's save () 
> method like this: 
>
> def save (self, *args, **kwargs):
>  if not self.slug:
> self.slug = slugify(self.title)
> super(Product, self).save (*args, **kwargs)
>
> This way, you can automatically generate the value of the slug field when 
> a valid form is submitted. 
>
> If you are still having problems, please, do let us know.
>
> All the best.
>
> Sincerely,
> Muhammad 
>
> On May 25, 2017 7:20 AM, "Ismail Sarenkapic"  > wrote:
>
> Hi, I'm trying to create a digital marketplace site where users will be 
> able to register and submit their products.
> I created the Product model and connected it with User with foreign 
> key.Everything seems  to be alright, but when I submit my product i get the 
> following error:
>
> null value in column violates not-null constraint
>  it looks like relation between product and user is not properly 
> configured(regardless of my mixin that is suppose to handle it)
>
> __
> note that I'm using:
>
> database:postgresql
>
> allauth(for user registration)
>
> __
>
> 
> models.py
>
> from django.conf import settings
> from django.db import models
> from django.db.models.signals import pre_save, post_save
> from django.core.urlresolvers import reverse
> from django.utils.text import slugify
> # Create your models here.
>
>
>
> class Product(models.Model):
>seller = models.ForeignKey(settings.AUTH_USER_MODEL)
>#user = models.OneToOneField(settings.AUTH_USER_MODEL)
># user = models.ForeignKey(settings.AUTH_USER_MODEL)
># managers = models.ManyToManyField(settings.AUTH_USER_MODEL, 
> related_name="managers_products", blank=True)
>title = models.CharField(max_length=30) 
> #owiuerpoajsdlfkjasd;flkiu1p3o4u134123 ewjfa;sd
>slug = models.SlugField(blank=True, unique=True)
>description = models.TextField()
>price = models.DecimalField(max_digits=100, decimal_places=2, 
> default=9.99, null=True,) #100.00
>
>
>def __unicode__(self): #def __unicode__(self):
>   return self.title
>
> ___
> views.py
>
>
> from django.views import View
> from django.views.generic import (
> CreateView,
> )
>
> from .forms import ProductModelForm
> from .mixins import FormUserNeededMixin
> # Create your views here.
>
>
> class ProductCreateView(FormUserNeededMixin, CreateView):
> form_class = ProductModelForm
> template_name = 'create_view.html'
>
> ___
> forms.py
>
> from django import forms
>
> from django.utils.text import slugify
>
> from .models import Product
>
>
> class ProductModelForm(forms.ModelForm):
>class Meta:
>   model = Product
>   fields = [
>  "title",
>  "description",
>  "price",
>   ]
>
> 
> mixins.py
>
> from django import forms
> from django.forms.utils import ErrorList
>
> class FormUserNeededMixin(object):
>
>  def form_valid(self, form):
> if self.request.user.is_authenticated():
> form.instance.user = self.request.user
> return super(FormUserNeededMixin, self).form_valid(form)
> else:
> form._errors[forms.forms.NON_FIELD_ERRORS] = ErrorList(["User 
> must be logged in to continue."])
> return self.form_invalid(form)
>
>
>
>
>
>
>
> -- 
> 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 https://groups.google.com/group/django-users.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/django-users/0d2d44eb-a2df-4f00-8d60-3f163ed72c9b%40googlegroups.com
>  
> 
> .
> 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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https

Re: null value in column violates not-null constraint

2017-05-25 Thread Vijay Khemlani
"form.instance.user"

should be

"form.instance.seller"

But the "null value in column" error could also apply to any of the
non-nullable fields in your Product model that are not set by the time
you save the instance.

On 5/25/17, Ismail Sarenkapic  wrote:
> Tnx.
> The slug is not important here.
> The main question is how do I add product  with current user!
>
> On Thursday, May 25, 2017 at 8:00:08 PM UTC+2, Muhammad wrote:
>>
>> Ismail,
>>
>> You don't seem to be handling the value for Product.slug anywhere, either
>>
>> in the model or the view.
>>
>> You can fix the slug issue by overriding the Product model's save ()
>> method like this:
>>
>> def save (self, *args, **kwargs):
>>  if not self.slug:
>> self.slug = slugify(self.title)
>> super(Product, self).save (*args, **kwargs)
>>
>> This way, you can automatically generate the value of the slug field when
>>
>> a valid form is submitted.
>>
>> If you are still having problems, please, do let us know.
>>
>> All the best.
>>
>> Sincerely,
>> Muhammad
>>
>> On May 25, 2017 7:20 AM, "Ismail Sarenkapic" > > wrote:
>>
>> Hi, I'm trying to create a digital marketplace site where users will be
>> able to register and submit their products.
>> I created the Product model and connected it with User with foreign
>> key.Everything seems  to be alright, but when I submit my product i get
>> the
>> following error:
>>
>> null value in column violates not-null constraint
>>  it looks like relation between product and user is not properly
>> configured(regardless of my mixin that is suppose to handle it)
>>
>> __
>> note that I'm using:
>>
>> database:postgresql
>>
>> allauth(for user registration)
>>
>> __
>>
>> 
>> models.py
>>
>> from django.conf import settings
>> from django.db import models
>> from django.db.models.signals import pre_save, post_save
>> from django.core.urlresolvers import reverse
>> from django.utils.text import slugify
>> # Create your models here.
>>
>>
>>
>> class Product(models.Model):
>>seller = models.ForeignKey(settings.AUTH_USER_MODEL)
>>#user = models.OneToOneField(settings.AUTH_USER_MODEL)
>># user = models.ForeignKey(settings.AUTH_USER_MODEL)
>># managers = models.ManyToManyField(settings.AUTH_USER_MODEL,
>> related_name="managers_products", blank=True)
>>title = models.CharField(max_length=30)
>> #owiuerpoajsdlfkjasd;flkiu1p3o4u134123 ewjfa;sd
>>slug = models.SlugField(blank=True, unique=True)
>>description = models.TextField()
>>price = models.DecimalField(max_digits=100, decimal_places=2,
>> default=9.99, null=True,) #100.00
>>
>>
>>def __unicode__(self): #def __unicode__(self):
>>   return self.title
>>
>> ___
>> views.py
>>
>>
>> from django.views import View
>> from django.views.generic import (
>> CreateView,
>> )
>>
>> from .forms import ProductModelForm
>> from .mixins import FormUserNeededMixin
>> # Create your views here.
>>
>>
>> class ProductCreateView(FormUserNeededMixin, CreateView):
>> form_class = ProductModelForm
>> template_name = 'create_view.html'
>>
>> ___
>> forms.py
>>
>> from django import forms
>>
>> from django.utils.text import slugify
>>
>> from .models import Product
>>
>>
>> class ProductModelForm(forms.ModelForm):
>>class Meta:
>>   model = Product
>>   fields = [
>>  "title",
>>  "description",
>>  "price",
>>   ]
>>
>> 
>> mixins.py
>>
>> from django import forms
>> from django.forms.utils import ErrorList
>>
>> class FormUserNeededMixin(object):
>>
>>  def form_valid(self, form):
>> if self.request.user.is_authenticated():
>> form.instance.user = self.request.user
>> return super(FormUserNeededMixin, self).form_valid(form)
>> else:
>> form._errors[forms.forms.NON_FIELD_ERRORS] = ErrorList(["User
>> must be logged in to continue."])
>> return self.form_invalid(form)
>>
>>
>>
>>
>>
>>
>>
>> --
>> 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 https://groups.google.com/group/django-users.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/0d2d44eb-a2df-4f00-8d60-3f163ed72c9b%40googlegroups.com
>>
>> 
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>>
>

Re: null value in column violates not-null constraint

2017-05-25 Thread Melvyn Sopacua
Let me spell it out:
If the error message complains about the user field
And the code you provided is correct
Then your database is out of sync with your model definition


On Thursday 25 May 2017 13:53:19 Ismail Sarenkapic wrote:
> Tnx ,
> I know that i can manually select the user, but i want it to be
> automatic-with current user to add the product
> 
> > > class Product(models.Model):
> > > seller = models.ForeignKey(settings.AUTH_USER_MODEL)
^ Here is the seller field

> > > 
> > > #user = models.OneToOneField(settings.AUTH_USER_MODEL)
^^^ There is no user field. form.instance.user = 'foo' does not translate 
to anything 
useful.
The FormUserNeededMixin sets Product.user, which simply adds an instance 
variable, that is 
not picked up by the ORM, because 'user' is not a field in Product.fields.

The error should actually be about a field called 'seller', but because it is 
not in the form, it is 
not passed to the ORM and the old table complains about the user field, as it 
is the one that it 
still has.

-- 
Melvyn Sopacua

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/2021711.abbbOG0kaK%40devstation.
For more options, visit https://groups.google.com/d/optout.


Re: best practices for handling charts

2017-05-25 Thread Melvyn Sopacua
On Tuesday 23 May 2017 06:25:16 Alceu Rodrigues de Freitas 
Junior wrote:
> (which will
> require that I use crontab or something like it to delete old 
files).

Which is a one-liner:
find /var/www/generated-graphs -mtime 14 -delete # delete 2-
week old files

Some solutions are easier then the problem description.
-- 
Melvyn Sopacua

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/8140820.FJpOJ5WDHk%40devstation.
For more options, visit https://groups.google.com/d/optout.


Re: Building correct queryset

2017-05-25 Thread Melvyn Sopacua
On Monday 22 May 2017 15:26:59 Todor Velichkov wrote:
> Hello, Дмитрий,
> you can try this one, but w/o further optimizations it may be a very
> slow query.
> 
> qs = Product.objects.filter(
> #Where score is greater or equal
> #to the 4th max score from its group
> score__gte=Subquery(
> (Product.objects
> .filter(brand=OuterRef('brand'))
> .values('score')
> .order_by('-score')[3:4]
> )
> )
> ).order_by('-score')

Yeah, that's how I read it too. But the code says score is on Brand model, not 
Product. 
Which is correct?
-- 
Melvyn Sopacua

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/1888330.h8aJiHRcfu%40devstation.
For more options, visit https://groups.google.com/d/optout.


Re: Building correct queryset

2017-05-25 Thread Горобец Дмитрий
Score field is on Brand model.

пятница, 26 мая 2017 г., 3:19:56 UTC+5 пользователь Melvyn Sopacua написал:
>
> On Monday 22 May 2017 15:26:59 Todor Velichkov wrote:
>
> > Hello, Дмитрий,
>
> > you can try this one, but w/o further optimizations it may be a very
>
> > slow query.
>
> > 
>
> > qs = Product.objects.filter(
>
> > #Where score is greater or equal
>
> > #to the 4th max score from its group
>
> > score__gte=Subquery(
>
> > (Product.objects
>
> > .filter(brand=OuterRef('brand'))
>
> > .values('score')
>
> > .order_by('-score')[3:4]
>
> > )
>
> > )
>
> > ).order_by('-score')
>
>  
>
> Yeah, that's how I read it too. But the code says score is on Brand model, 
> not Product. Which is correct?
>
> -- 
>
> Melvyn Sopacua
>

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/5838210b-f4ea-4338-ab2c-7c6e706acae2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: null value in column violates not-null constraint

2017-05-25 Thread Ismail Sarenkapic
Man this solved my problem, I can't believe that is spend few hours not 
seeing this
But now that I am able to create products with my current user, i have 
another problem:

When I login with admin while I am logged in with my current user, and then 
create product,
product is being added as by admin not as by current user as it should be.
otherwise when I am not logged in with admin(but only with current user) 
everything seems to work fine.
Can you help me maybe with this one?
Thanks.
On Thursday, May 25, 2017 at 11:19:11 PM UTC+2, Vijay Khemlani wrote:
>
> "form.instance.user" 
>
> should be 
>
> "form.instance.seller" 
>
> But the "null value in column" error could also apply to any of the 
> non-nullable fields in your Product model that are not set by the time 
> you save the instance. 
>
> On 5/25/17, Ismail Sarenkapic > wrote: 
> > Tnx. 
> > The slug is not important here. 
> > The main question is how do I add product  with current user! 
> > 
> > On Thursday, May 25, 2017 at 8:00:08 PM UTC+2, Muhammad wrote: 
> >> 
> >> Ismail, 
> >> 
> >> You don't seem to be handling the value for Product.slug anywhere, 
> either 
> >> 
> >> in the model or the view. 
> >> 
> >> You can fix the slug issue by overriding the Product model's save () 
> >> method like this: 
> >> 
> >> def save (self, *args, **kwargs): 
> >>  if not self.slug: 
> >> self.slug = slugify(self.title) 
> >> super(Product, self).save (*args, **kwargs) 
> >> 
> >> This way, you can automatically generate the value of the slug field 
> when 
> >> 
> >> a valid form is submitted. 
> >> 
> >> If you are still having problems, please, do let us know. 
> >> 
> >> All the best. 
> >> 
> >> Sincerely, 
> >> Muhammad 
> >> 
> >> On May 25, 2017 7:20 AM, "Ismail Sarenkapic"  >> > wrote: 
> >> 
> >> Hi, I'm trying to create a digital marketplace site where users will be 
> >> able to register and submit their products. 
> >> I created the Product model and connected it with User with foreign 
> >> key.Everything seems  to be alright, but when I submit my product i get 
> >> the 
> >> following error: 
> >> 
> >> null value in column violates not-null constraint 
> >>  it looks like relation between product and user is not properly 
> >> configured(regardless of my mixin that is suppose to handle it) 
> >> 
> >> 
> __
>  
>
> >> note that I'm using: 
> >> 
> >> database:postgresql 
> >> 
> >> allauth(for user registration) 
> >> 
> >> 
> __
>  
>
> >> 
> >>  
> >> models.py 
> >> 
> >> from django.conf import settings 
> >> from django.db import models 
> >> from django.db.models.signals import pre_save, post_save 
> >> from django.core.urlresolvers import reverse 
> >> from django.utils.text import slugify 
> >> # Create your models here. 
> >> 
> >> 
> >> 
> >> class Product(models.Model): 
> >>seller = models.ForeignKey(settings.AUTH_USER_MODEL) 
> >>#user = models.OneToOneField(settings.AUTH_USER_MODEL) 
> >># user = models.ForeignKey(settings.AUTH_USER_MODEL) 
> >># managers = models.ManyToManyField(settings.AUTH_USER_MODEL, 
> >> related_name="managers_products", blank=True) 
> >>title = models.CharField(max_length=30) 
> >> #owiuerpoajsdlfkjasd;flkiu1p3o4u134123 ewjfa;sd 
> >>slug = models.SlugField(blank=True, unique=True) 
> >>description = models.TextField() 
> >>price = models.DecimalField(max_digits=100, decimal_places=2, 
> >> default=9.99, null=True,) #100.00 
> >> 
> >> 
> >>def __unicode__(self): #def __unicode__(self): 
> >>   return self.title 
> >> 
> >> ___ 
> >> views.py 
> >> 
> >> 
> >> from django.views import View 
> >> from django.views.generic import ( 
> >> CreateView, 
> >> ) 
> >> 
> >> from .forms import ProductModelForm 
> >> from .mixins import FormUserNeededMixin 
> >> # Create your views here. 
> >> 
> >> 
> >> class ProductCreateView(FormUserNeededMixin, CreateView): 
> >> form_class = ProductModelForm 
> >> template_name = 'create_view.html' 
> >> 
> >> ___ 
> >> forms.py 
> >> 
> >> from django import forms 
> >> 
> >> from django.utils.text import slugify 
> >> 
> >> from .models import Product 
> >> 
> >> 
> >> class ProductModelForm(forms.ModelForm): 
> >>class Meta: 
> >>   model = Product 
> >>   fields = [ 
> >>  "title", 
> >>  "description", 
> >>  "price", 
> >>   ] 
> >> 
> >>  
> >> mixins.py 
> >> 
> >> from django import forms 
> >> from django.forms.utils import ErrorList 
> >> 
> >> class FormUserNeededMixin(object): 
> >> 
> >>  def form_valid(self, form): 
> >> if self.request.user.is_authenticated(): 
> >> form.instance.user = self.request.user 
> >>   

Re: null value in column violates not-null constraint

2017-05-25 Thread Ismail Sarenkapic
Thanks for answering man!

On Thursday, May 25, 2017 at 11:44:08 PM UTC+2, Melvyn Sopacua wrote:
>
> Let me spell it out:
>
> If the error message complains about the user field
>
> And the code you provided is correct
>
> Then your database is out of sync with your model definition
>
>  
>
>  
>
> On Thursday 25 May 2017 13:53:19 Ismail Sarenkapic wrote:
>
> > Tnx ,
>
> > I know that i can manually select the user, but i want it to be
>
> > automatic-with current user to add the product
>
> > 
>
> > > > class Product(models.Model):
>
> > > > seller = models.ForeignKey(settings.AUTH_USER_MODEL)
>
> ^ Here is the seller field
>
>  
>
> > > > 
>
> > > > #user = models.OneToOneField(settings.AUTH_USER_MODEL)
>
> ^^^ There is no user field. form.instance.user = 'foo' does not 
> translate to anything useful.
>
> The FormUserNeededMixin sets Product.user, which simply adds an instance 
> variable, that is not picked up by the ORM, because 'user' is not a field 
> in Product.fields.
>
>  
>
> The error should actually be about a field called 'seller', but because it 
> is not in the form, it is not passed to the ORM and the old table complains 
> about the user field, as it is the one that it still has.
>
>  
>
> -- 
>
> Melvyn Sopacua
>

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/7a5e9188-4b9a-4f4b-802f-3683cdd7e127%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.