Please I need help on how to create a custom method for a model with list_display

2018-05-19 Thread Godson Rapture


Please I am learning Django 2.0.4


Right now I am learning about Django Admin.


I got an error that the value of my list_display should not be a ManyToMany 
Field.


I referred back to Django official doc and I was asked to create a custom 
method for my model.


I tried looking for an example of how to do that, I could not see.


Here is my model.py program

 from django.db import models

class Publisher(models.Model):
name = models.CharField(max_length=30)
address = models.CharField(max_length=50,blank=True)
city = models.CharField(max_length=60,blank=True)
country = models.CharField(max_length=50,blank=True)
website = models.URLField()
def __str__(self):
return self.name

class Author(models.Model):
salution = models.CharField(max_length=10)
first_name = models.CharField(max_length=30)
last_name = models.CharField(max_length=40)
email = models.EmailField()
headshot = models.ImageField(upload_to = "tmp")
def __str__(self):
return f"{self.first_name} {self.last_name}"

class Book(models.Model):
title = models.CharField(max_length=100)
authors = models.ManyToManyField(Author)
publisher = models.ForeignKey(Publisher,on_delete=models.CASCADE,)
publication_date = models.DateField()
def __str__(self):
return self.title

Here is my admin.py program

from django.contrib import admin
from polls.models import Book, Publisher, Author
# Register your models here.

class BookAdmin(admin.ModelAdmin):
list_display = [
"title",
"authors", #a ManyToMany Field

]
 search_fields = [
"Book"
]
class Meta:
model = Book

admin.site.register(Book, BookAdmin)

Can someone please help me.

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/c2574ad9-e4cb-4b21-a255-8eb9db40ab9f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Please I need help on how to create a custom method for a model with list_display

2018-05-20 Thread Godson Rapture
Thanks very much. I have solved the problem.

On Sunday, May 20, 2018, Daniel Germano Travieso 
wrote:

> Hello!
>
> On your case, as stated on the official doc, you should just create a
> method on the model you want to display the ManyToMany field on the
> list_display that maybe returns the list of items from the ManyToMany
> field. Django avoids using this as it could be a potential overhead as you
> will run seperate queries on the database to fetch all the related
> many-to-many objects.
>
> But if you are feeling adventurous, just create the method that performs
> that query.
>
> i.e. On your Book model you create a method that returns the
> self.authors.all() set. Then you use that method's name on the list_display
> instead of authors.
>
> Hope it helps.
>
> On Saturday, May 19, 2018 at 3:54:17 PM UTC-3, Godson Rapture wrote:
>>
>> Please I am learning Django 2.0.4
>>
>>
>> Right now I am learning about Django Admin.
>>
>>
>> I got an error that the value of my list_display should not be a
>> ManyToMany Field.
>>
>>
>> I referred back to Django official doc and I was asked to create a custom
>> method for my model.
>>
>>
>> I tried looking for an example of how to do that, I could not see.
>>
>>
>> Here is my model.py program
>>
>>  from django.db import models
>>
>> class Publisher(models.Model):
>> name = models.CharField(max_length=30)
>> address = models.CharField(max_length=50,blank=True)
>> city = models.CharField(max_length=60,blank=True)
>> country = models.CharField(max_length=50,blank=True)
>> website = models.URLField()
>> def __str__(self):
>> return self.name
>>
>> class Author(models.Model):
>> salution = models.CharField(max_length=10)
>> first_name = models.CharField(max_length=30)
>> last_name = models.CharField(max_length=40)
>> email = models.EmailField()
>> headshot = models.ImageField(upload_to = "tmp")
>> def __str__(self):
>> return f"{self.first_name} {self.last_name}"
>>
>> class Book(models.Model):
>> title = models.CharField(max_length=100)
>> authors = models.ManyToManyField(Author)
>> publisher = models.ForeignKey(Publisher,on_delete=models.CASCADE,)
>> publication_date = models.DateField()
>> def __str__(self):
>> return self.title
>>
>> Here is my admin.py program
>>
>> from django.contrib import admin
>> from polls.models import Book, Publisher, Author
>> # Register your models here.
>>
>> class BookAdmin(admin.ModelAdmin):
>> list_display = [
>> "title",
>> "authors", #a ManyToMany Field
>>
>> ]
>>  search_fields = [
>> "Book"
>> ]
>> class Meta:
>> model = Book
>>
>> admin.site.register(Book, BookAdmin)
>>
>> Can someone please help me.
>>
>> 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/56c58fb6-7074-47aa-9536-8d8027ef70a0%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/56c58fb6-7074-47aa-9536-8d8027ef70a0%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> 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/CAEUEpOR37QtBN72gczc9JKteiB5rBryL3vhXP1capNtc1UsLZQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


inserting data in a DateTimeField() in Django by using datetime-local

2018-12-07 Thread Godson Rapture
Please, I am creating a to-do list app as my first django project.

My form is not valid because I am trying to insert DateTimeField in django
using datetime-local.

I did research, I discovered I need to do a custom model so I parse the
datetime-local field.

Pls guide me on how to create a custom model field.

-- 
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/CAEUEpOQkk58EpVZd_PHN77aMnr-k2%2BbbhheYDistYqm2Lxfa%3DA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Best Learning Resources

2019-01-16 Thread Godson Rapture
Check out the book "django for beginners "

On Wed, Jan 16, 2019, 2:19 PM  wrote:

> Hi All,
>
> I'm just starting out with Django and python and wondering if anyone can
> direct me to some goto learning resources. Beginner to Advanced
>
> 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/82db4a06-5a19-43c5-9d04-b3007a45173d%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/CAEUEpOTbj5hKQmOzDkX6xtQT_xCmiKdAeHvQ%3DG3OqK-%3D_30QOw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Pagination - Not Working

2019-02-19 Thread Godson Rapture
Can you upload your code on github let me check where your problem is?

On Tue, Feb 19, 2019, 6:43 AM Siddharth Tamang 
wrote:

> Are you trying pagination using JavaScript or Django?
>
> On Mon, Feb 18, 2019 at 11:47 PM Aakash Baranwal 
> wrote:
>
>> Hello Everyone,
>>
>> I am new to Django and working towards developing a web app where 10
>> posts appear at a time with a "Load More" option given at last which when
>> clicked shows the next 10 posts. I am not able to find what is going wrong
>> with the code.
>>
>> Also, it is not showing the character counter for the textbox, so kindly
>> help me with that as well.
>>
>> I am sending the screenshot of the code, pagination.py file.
>>
>> Thank You in advance
>>
>> --
>> 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/CALr9hQ02EKRB%3DUjPfgjX1Q1%2BG_QxxBovM7Xv_J9Y-Q%3DiwMLo_A%40mail.gmail.com
>> 
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
> --
> Thank you
> Siddharth Tamang
> AWS Certified Solutions Architect - Associate
>
> --
> 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/CADBOudsyrwDg%3DzcG3SgFMVnosOUtym%2BeR3d7UPXEa9GnRz7Opw%40mail.gmail.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/CAEUEpOTUP_-rdoY8p4%2BfT4%2BTEmCLoSFyLQ1L%3DsdhfPkeHtY3rw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Pagination - Not Working

2019-02-19 Thread Godson Rapture
Check out simple is better than complex blog. It should have a topic on
pagination to help you

On Tue, Feb 19, 2019, 9:20 AM Aakash Baranwal  wrote:

> Hello,
>
> Thanks for offering me your help, but the problem is I can't upload it on
> internet as I have signed a Non Disclosure Agreement for the project in
> which I am working, so totally helpless in this case.
>
> However I might be able to give a specific portion of what you might need
> for resolving this issue.
>
> I am extremely sorry about this.
>
> On Tue, Feb 19, 2019 at 1:38 PM Godson Rapture 
> wrote:
>
>> Can you upload your code on github let me check where your problem is?
>>
>> On Tue, Feb 19, 2019, 6:43 AM Siddharth Tamang <
>> tamangsiddhart...@gmail.com> wrote:
>>
>>> Are you trying pagination using JavaScript or Django?
>>>
>>> On Mon, Feb 18, 2019 at 11:47 PM Aakash Baranwal 
>>> wrote:
>>>
>>>> Hello Everyone,
>>>>
>>>> I am new to Django and working towards developing a web app where 10
>>>> posts appear at a time with a "Load More" option given at last which when
>>>> clicked shows the next 10 posts. I am not able to find what is going wrong
>>>> with the code.
>>>>
>>>> Also, it is not showing the character counter for the textbox, so
>>>> kindly help me with that as well.
>>>>
>>>> I am sending the screenshot of the code, pagination.py file.
>>>>
>>>> Thank You in advance
>>>>
>>>> --
>>>> 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/CALr9hQ02EKRB%3DUjPfgjX1Q1%2BG_QxxBovM7Xv_J9Y-Q%3DiwMLo_A%40mail.gmail.com
>>>> <https://groups.google.com/d/msgid/django-users/CALr9hQ02EKRB%3DUjPfgjX1Q1%2BG_QxxBovM7Xv_J9Y-Q%3DiwMLo_A%40mail.gmail.com?utm_medium=email&utm_source=footer>
>>>> .
>>>> For more options, visit https://groups.google.com/d/optout.
>>>>
>>>
>>>
>>> --
>>> Thank you
>>> Siddharth Tamang
>>> AWS Certified Solutions Architect - Associate
>>>
>>> --
>>> 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/CADBOudsyrwDg%3DzcG3SgFMVnosOUtym%2BeR3d7UPXEa9GnRz7Opw%40mail.gmail.com
>>> <https://groups.google.com/d/msgid/django-users/CADBOudsyrwDg%3DzcG3SgFMVnosOUtym%2BeR3d7UPXEa9GnRz7Opw%40mail.gmail.com?utm_medium=email&utm_source=footer>
>>> .
>>> 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/CAEUEpOTUP_-rdoY8p4%2BfT4%2BTEmCLoSFyLQ1L%3DsdhfPkeHtY3rw%40mail.gmail.com
>> <https://groups.google.com/d/msgid/django-users/CAEUEpOTUP_-rdoY8p4%2BfT4%2BTEmCLoSFyLQ1L%3DsdhfPkeHtY3rw%40mail.gmail.com?utm_medium=email&utm_source=footer>
>> .
>> 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 gro