These are chat archives for django/django

13th
Apr 2016
Zeeshan Asgar
@asgarzee
Apr 13 2016 07:07

hi guys. I want to implement permalink in my app. Any Suggestions how to do that.

https://docs.djangoproject.com/en/1.9/ref/urls/#include

like the above url (#include).

Filip Figiel
@megapctr
Apr 13 2016 07:16
Not really a Django question. It's in html
You make a div (or anything) with id, like foo
Zeeshan Asgar
@asgarzee
Apr 13 2016 07:16
@megapctr but how do i set it in urls.py
Filip Figiel
@megapctr
Apr 13 2016 07:17
Then you link to it with the a tat and href #foo
It has nothing to do with your backend dude
Zeeshan Asgar
@asgarzee
Apr 13 2016 07:17
i have done that but not working
Filip Figiel
@megapctr
Apr 13 2016 07:17
*a tag, not tat :)
Zeeshan Asgar
@asgarzee
Apr 13 2016 07:18
haha.... it's doing nothing
Filip Figiel
@megapctr
Apr 13 2016 07:18
What have you done?
Zeeshan Asgar
@asgarzee
Apr 13 2016 07:18
wait
i will show u
samkurma
@samkurma
Apr 13 2016 07:19
I am getting migrations error in django==1.9, which version should i use for custom user model?
Filip Figiel
@megapctr
Apr 13 2016 07:20
Let me get my crystal ball
Zeeshan Asgar
@asgarzee
Apr 13 2016 07:20

<a href="#{{error.code}}"> </a>
i have done this in my template where error is the object
Filip Figiel
@megapctr
Apr 13 2016 07:20
You have to put some text into the tag
Otherwise it won't render
Zeeshan Asgar
@asgarzee
Apr 13 2016 07:20
yeah i know
text is there in the template
Filip Figiel
@megapctr
Apr 13 2016 07:21
And how do you render the error?
samkurma
@samkurma
Apr 13 2016 07:21
@megapctr could you please suggest me, which stable version should i use?
Filip Figiel
@megapctr
Apr 13 2016 07:22
@samkurma i can't help you if you can't even describe your problem. What is the error you're getting? What are you trying to do?
Zeeshan Asgar
@asgarzee
Apr 13 2016 07:22
return render(request, 'errordetail.html', {'errors': errors})
Filip Figiel
@megapctr
Apr 13 2016 07:23
@asgarzee i mean in the HTML. You should have a tag with ID same as your href attribute (Sans the hash)
Zeeshan Asgar
@asgarzee
Apr 13 2016 07:23
{% for error in errors%}
<a href="#{{error.code}}"> <h1>Error: {{error.code}}</h1></a>
<h2>{{error.message}}</h2>
<p>{{error.desc}}</p>
{% endfor %}
samkurma
@samkurma
Apr 13 2016 07:24
i am using django 1.9 version, when i am trying to migrate with custom user model, i am getting: raise ValueError('Related model %r cannot be resolved' % self.remote_field.model)
ValueError: Related model 'registrations.MyUser' cannot be resolved
could yo please suggest me
Filip Figiel
@megapctr
Apr 13 2016 07:24
@asgarzee did you read me? You have to add an ID attribute
Zeeshan Asgar
@asgarzee
Apr 13 2016 07:25
okay
samkurma
@samkurma
Apr 13 2016 07:25
@megapctr Do you want me post my custom user model?
Filip Figiel
@megapctr
Apr 13 2016 07:26
@samkurma do you have a model in the app? Are the names correct?
Zeeshan Asgar
@asgarzee
Apr 13 2016 07:27
{% for error in errors%}
<a href="#{{error.code}}"> <h1 id="{{error.code}}">Error: {{error.code}}</h1></a>
<h2>{{error.message}}</h2>
<p>{{error.desc}}</p>
{% endfor %}
@megapctr like this
Filip Figiel
@megapctr
Apr 13 2016 07:27
Yep
Zeeshan Asgar
@asgarzee
Apr 13 2016 07:27
okay thanks
samkurma
@samkurma
Apr 13 2016 07:27
@megapctr This is my custom user model::::

from django.contrib.auth.models import (AbstractBaseUser, BaseUserManager)

class MyUserManager(BaseUserManager):

def create_user(self, email, password=None):
    if not email:
        raise ValueError('Users must have an email address')

    user = self.model(
        email=MyUserManager.normalize_email(email),
    )

    user.set_password(password)
    print "self._db {0}".format(self._db)
    user.save(using=self._db)
    return user

def create_superuser(self, email, password):
    user = self.create_user(email,
        password=password,
    )
    user.is_admin = True
    user.save(using=self._db)
    return user

class MyUser(AbstractBaseUser):

email = models.EmailField(
    verbose_name='email address',
    max_length=255,
    unique=True,
)
created_on = models.DateTimeField(auto_now_add=True)
is_active = models.BooleanField(default=True)
is_admin = models.BooleanField(default=False)

objects = MyUserManager()

USERNAME_FIELD = 'email'

def get_full_name(self):
    # The user is identified by their email address
    return self.email

def get_short_name(self):
    # The user is identified by their email address
    return self.email

def __str__(self):              # __unicode__ on Python 2
    return self.email

def has_perm(self, perm, obj=None):
    "Does the user have a specific permission?"
    # Simplest possible answer: Yes, always
    return True

def has_module_perms(self, app_label):
    "Does the user have permissions to view the app `app_label`?"
    # Simplest possible answer: Yes, always
    return True

@property
def is_staff(self):
    "Is the user a member of staff?"
    # Simplest possible answer: All admins are staff
    return self.is_admin
Filip Figiel
@megapctr
Apr 13 2016 07:28
@samkurma you should have a folder named registrations, and inside models.py file with MyUser class
samkurma
@samkurma
Apr 13 2016 07:28
AUTH_USER_MODEL = 'registrations.MyUser'
Filip Figiel
@megapctr
Apr 13 2016 07:29
Do you have registrations in your installed apps?
Zeeshan Asgar
@asgarzee
Apr 13 2016 07:35
@megapctr thanks. It worked
samkurma
@samkurma
Apr 13 2016 07:42
@megapctr i have the folder with registrations name and in that models file i put the custom user model code
can you please help me in that?
samkurma
@samkurma
Apr 13 2016 07:49
is the 1.9 version stable?
Filip Figiel
@megapctr
Apr 13 2016 09:05
of course it is
sumit sinha
@sumitsinha91
Apr 13 2016 11:18
help me for unittest related documents i am new on unittest
Job Matheka
@jobm
Apr 13 2016 12:05
hey everyone so i have a model that owns other models like:
```class Student(models.Model):
pass
Job Matheka
@jobm
Apr 13 2016 12:17
sorry guys was typig and lost everything, let me reprase my question.
Job Matheka
@jobm
Apr 13 2016 12:30

So this is a the structure of my models, not everything is included

   class Follower(models.Model):
       follower = models.OneToOneField(User, unique=True, blank=True)

   class Chef(models.Model):
       owner = models.OneToOneField(User, primary_key=True)
       followers = models.ManyToManyField(Follower)
       """the rest of the models fields here"""


   class Kitchen(models.Model):
       owner = models.OneToOneField(Chef, primary_key=True)
       """the rest of the models fields here"""


   class Menu(models.Model):
       owner = models.ForeignKey(Kitchen)
       """the rest of the models fields here"""


   class Recipe(models.Model):
       owner = models.ForeignKey(Kitchen)
       """the rest of the models fields here"""

   class Conversation(models.Model):
       owner = models.ForeignKey(Kitchen)
       """the rest of the models fields here"""

so am using a very crude way of querying the data from the above models like,

    chef = get_object_or_none(Chef, owner_id = request.user.id)
    kitchen = get_object_or_none(Kitchen, owner=chef)
    menus = filter_object_or_none(Menu, owner=kitchen)
    recipes = filter_object_or_none(Recipe, owner=kitchen)
    conversations = filter_object_or_none(Conversation, owner=kitchen)

am very new to django and i know there is definately a better way of doing this,
so pardon my terrible code above but can someone please guide me into doing it better?
Thanks in advance.

Filip Figiel
@megapctr
Apr 13 2016 13:03
@jobm read django documentation for querysets
for reverse ForeignKey lookups, you can do conversations = kitchen.conversation_set.all()
{fieldName}_set is the default name for the reverse fk lookups
Job Matheka
@jobm
Apr 13 2016 13:06
thank you @megapctr, are you refering to this this documentation https://docs.djangoproject.com/en/1.9/ref/models/querysets/ ?
samkurma
@samkurma
Apr 13 2016 13:17
why do we get this error?
File "/home/sambaiah/.virtualenvs/Bits/local/lib/python2.7/site-packages/django/db/models/base.py", line 850, in _do_insert
return manager._insert([self], fields=fields, return_id=update_pk,
AttributeError: 'NoneType' object has no attribute '_insert'
Jesús Gómez
@jgomo3
Apr 13 2016 15:08
This is old, but: did you read this proposal?
Puneet Aggarwal
@puneetagg
Apr 13 2016 15:53
Hi..
I am trying to use django-rest-framework-social-oauth2..but I am getting error:
ImportError: No module named packages.urllib3.poolmanager
gmwill92
@gmwill92
Apr 13 2016 17:45
anyone has build django and angular applications?
Puneet Aggarwal
@puneetagg
Apr 13 2016 17:50
@gmwill92 I am currently working on one.
gmwill92
@gmwill92
Apr 13 2016 17:51
@puneetagg what does it do? can you share your experience?
Puneet Aggarwal
@puneetagg
Apr 13 2016 17:53
@gmwill92 I have used DRF for the REST APIs. Being a beginner to both, faced lots of issues and even now stuck on one. But community support is amazing for both.
gmwill92
@gmwill92
Apr 13 2016 17:55
@puneetagg What does the application do? I'm going to develop a CRM/Configure Price quote tool and currently, I'm evaluating which technologies to use.
Puneet Aggarwal
@puneetagg
Apr 13 2016 17:58
@gmwill92 I think django and angular would work great hand in hand. But there are some open source CRM solutions as well. Have a look on those. Use udacity for the courses. They tell about lots of new technologies.
gmwill92
@gmwill92
Apr 13 2016 17:59
@puneetagg thanks for the input!
aaskat
@aaskat
Apr 13 2016 18:03
hello
Puneet Aggarwal
@puneetagg
Apr 13 2016 18:05
Hi..
Is it possible to use django-allauth with DRF as I having setup issues with django-rest-framework-social-oauth2?
Dr M. Kaddour YAHYAOUI
@tuxador
Apr 13 2016 20:30
I have issues with pdf generation using LaTeX. Any good tutorials here?
Filip Figiel
@megapctr
Apr 13 2016 20:59
@tuxador check out weasyprint