These are chat archives for django/django

18th
Sep 2017
:]
@elcolie
Sep 18 2017 06:55
Hi

I have a question on the doc. https://docs.djangoproject.com/en/1.11/ref/contrib/gis/install/postgis/
What does ... means in this context?
Suppose I want to use postgis, and postgis_topology extensions.

from django.contrib.postgres.operations import CreateExtension
from django.db import migrations

class Migration(migrations.Migration):

    operations = [
        CreateExtension('postgis'),
        CreateExtension('postgis_topology'),
    ]

And put it as a one of the migration file. At any place?

Miracle Ayodele
@iammiracle
Sep 18 2017 09:17
Hi guys, i am having issues on which pattern of views to follow
function based view or class based views and i will like some tips on why
thanks
Pawel
@odwrotnie
Sep 18 2017 12:03
Are you able to connect https://github.com/applegrew/django-select2 in every select you have in your application? I am looking for systemwide solution - to replace the default.
Oğuzhan Yılmaz
@oguzhan-yilmaz
Sep 18 2017 12:50
@elcolie hey, if you are using postgresql, just open up your pgAdmin and add extension there
first you should download the extension from stackbuilder
talk2shruthivs
@talk2shruthivs
Sep 18 2017 13:13
Hey guys
@python_2_unicode_compatible
class Message(models.Model):
"""
A private directmessage
"""
content = models.TextField(_('Content'))
sender = models.ForeignKey(AUTH_USER_MODEL, related_name='sent_dm', verbosename=("Sender"))
recipient = models.ForeignKey(AUTH_USER_MODEL, related_name='received_dm', verbosename=("Recipient"))
sentat = models.DateTimeField(("sent at"), null=True, blank=True)
readat = models.DateTimeField(("read at"), null=True, blank=True)
@property
def unread(self):
    """returns whether the message was read or not"""
    if self.read_at is not None:
        return False
    return True

def __str__(self):
    return self.content

def save(self, **kwargs):
    if self.sender == self.recipient:
        raise ValidationError("You can't send messages to yourself")

    if not self.id:
        self.sent_at = timezone.now()
    super(Message, self).save(**kwargs)
<a href="{% url 'message_details' usr=contact pk=contact.pk %}">{{contact}}</a>
url(r'^messages/(?P<pk>\d+)/$', views.message_details, name='message_details')
def message_details(request, pk, usr):
conversation = Inbox.get_conversation(request.user, usr.User)
return render(request, 'blog/messages.html', {'conversation' : conversation})
def get_conversations(self, user):
    """
    Lists all conversation-partners for a specific user
    :param user: User
    :return: Conversation list
    """
    all_conversations = Message.objects.all().filter(Q(sender=user) | Q(recipient=user))

    contacts = []
    for conversation in all_conversations:
        if conversation.sender != user:
            contacts.append(conversation.sender)
        elif conversation.recipient != user:
            contacts.append(conversation.recipient)

    # To abolish duplicates
    return list(set(contacts))
<a href="{% url 'message_details' usr=contact pk=contact.pk %}">{{contact}}</a>
I want to pass sender details to my views.py from my html file
how can i do it ?
Anish Shrestha
@annshress
Sep 18 2017 13:38
@flyboy1565 I absolutely got busy. Really sorry. Finally came here to ask a question.

https://stackoverflow.com/questions/43009538/use-custom-filter-with-django-modelchoice-filter

This question pretty much sums up my problem.
The method filter does not get called.

Anyone knows the fix...