These are chat archives for django/django

11th
Apr 2017
John
@flyboy1565
Apr 11 2017 00:47
@koderNeptune , are you using timezones or are you using utc?
@chrisRubiano , are we talking in a query set or just in a model in general. If you are talking model in general, my question would be , do you have an automated I'd field?
Miracle Ayodele
@iammiracle
Apr 11 2017 06:44
utc
@flyboy1565 i am using utc
John
@flyboy1565
Apr 11 2017 07:16
Are you using the date time in templates tags?
BELLO MUSA
@Musbell
Apr 11 2017 08:53
I want to work on a fingerprint attendance system project . Kinda wanna know how it could be implemented with django .
Hello
Anish Shrestha
@annshress
Apr 11 2017 10:12
@Musbell It is rather a Python related question than django i guess.
prashant-sirohi
@prashant-sirohi
Apr 11 2017 10:13
Anyone has any idea how can i get a file from samba server and display it in chrome browser(template.html) without disabling its security features
Sopan
@sopanshewale
Apr 11 2017 10:52
Quick Question - is WebSocket support available in Django?
Article Translation
@ArsenalLevel3
Apr 11 2017 10:52
Maybe
Charles Roberts
@charles545587
Apr 11 2017 13:17

Hi I have a quick question concerning settings.py and local_settings.py

I have all my database credentials in local_settings.py and they are being pulled into settings.py.
I wanted to do the same with some AWS credentials but I got an error. Putting them back in settings.py resolved it.

Any ideas what is going on?

DanielAlderman
@DanielAlderman
Apr 11 2017 13:27
@charles545587 What's the error Charles?
Charles Roberts
@charles545587
Apr 11 2017 14:03
'NoneType' object is not callable
'AWS_STORAGE_BUCKET_NAME' is not defined
It is defined, but in local_settings.py
if it is in the main setting.py file then it works okay
DanielAlderman
@DanielAlderman
Apr 11 2017 14:09
Can you show me your import string for local_settings.py?
Charles Roberts
@charles545587
Apr 11 2017 14:10
f = os.path.join(PROJECT_APP_PATH, "local_settings.py")
if os.path.exists(f):
import sys
import imp
module_name = "%s.local_settings" % PROJECT_APP
module = imp.new_module(module_name)
module.file = f
sys.modules[module_name] = module
exec(open(f, "rb").read())
cs89gr
@cs89gr
Apr 11 2017 14:37

hello

if i want to create a query in django with to take all images and preview that list in html like easy work.

but if want in html page preview only the personal images where login user what changes i need in my code ?

model.py

class MyModel(models.Model):
    user = models.ForeignKey(User, unique=True)
    photo = models.ImageField(upload_to='images')

views.py

class BasicUploadView(request):
        photos_list = Photo.objects.all()
        return render(request, 'photos/basic_upload/index.html', {'photos': photos_list})

html page :

  {% for photo in photos %}
        <tr>
          <td><a href="{{ photo.file.url }}">{{ photo.file.name }}</a></td>
        </tr>
      {% endfor %}
John
@flyboy1565
Apr 11 2017 14:55
If user.is_authenticated
cs89gr
@cs89gr
Apr 11 2017 14:59
i want user see only personal images not all images from users
John
@flyboy1565
Apr 11 2017 15:22
Ok, well then I would do a query set
photo isn't and object.. it would be MyModel.objects.Filter(user=request.get.USER)
cs89gr
@cs89gr
Apr 11 2017 15:30
in views.py and i keep my code in html right ?
John
@flyboy1565
Apr 11 2017 15:34
Yup the only thing you'll be changing is the view statement
cs89gr
@cs89gr
Apr 11 2017 15:41
yes thnx you
Philip Eckert
@pae4557
Apr 11 2017 16:31
What version is everyone on? How big of a deal is updating?
Cristian Samaniego
@chrisRubiano
Apr 11 2017 16:35
@flyboy1565 I cant really tell the difference but here is my situation: i have a Course model which has many Chapters, and im trying to add navigation buttons inside every chapter template to directo next and prev chapters but only from that course
so i added these methods inside my Chapter model:
def get_next_slug(self):
    next = Chapter.objects.filter(id__gt=self.id).filter(course=self.course)
    if next:
        return next.first().slug
    return None

def get_prev_slug(self):
    prev = Chapter.objects.filter(id__lt=self.id).filter(course=self.course).order_by('-id')
    if prev:
        return prev.first().slug
    return None
John
@flyboy1565
Apr 11 2017 16:36
@chrisRubiano , can you provide your models for Course and Chapters?
Cristian Samaniego
@chrisRubiano
Apr 11 2017 16:37
sorry im having trouble pasting code haha
Cristian Samaniego
@chrisRubiano
Apr 11 2017 16:42
And heres the code in the template for course details, but it doesnt show the button
{% if chapter.get_previous_slug is not None %}
    <a href="{% url 'courses:chapter_details' course.slug chapter.get_prev_slug %}" type="button" class="btn btn-secondary mb-1 pull-left"><i class="fa fa-chevron-left"></i> Capítulo anterior</a>
{% endif %}
{% if chapter.get_previous_slug is not None %}
    <a href="{% url 'courses:chapter_details' course.slug chapter.get_next_slug %}" type="button" class="btn btn-secondary mb-1 pull-right">Siguiente capítulo <i class="fa fa-chevron-right"></i></a>
{% endif %}
These are the Course and Chapter models:
@python_2_unicode_compatible
class Course(models.Model):
    def get_image_path(self, filename):
        return os.path.join('courses', str(self.slug), filename)

    def __str__(self):
        return self.name

    def save(self, *args, **kwargs):
        self.slug = slugify(self.name)
        super(Course, self).save(*args, **kwargs)

    name = models.CharField(max_length=255, verbose_name="Nombre")
    description = models.CharField(max_length=255, verbose_name="Descripción")
    price = models.DecimalField(max_digits=12, decimal_places=2, verbose_name="Precio")
    slug = models.SlugField(blank=True, max_length=255)
    icon_img = models.ImageField(upload_to=get_image_path, blank=True, null=True, verbose_name="Imagen")
    background_color = ColorField(default="#026085")

    class Meta:
        verbose_name = "curso"
        verbose_name_plural = "cursos"


@python_2_unicode_compatible
class Chapter(models.Model):
    def get_video_path(self, filename):
        return os.path.join('videos', str(self.slug), filename)

    def get_next_slug(self):
        next = Chapter.objects.filter(id__gt=self.id).filter(course=self.course)
        if next:
            return next.first().slug
        return None

    def get_prev_slug(self):
        prev = Chapter.objects.filter(id__lt=self.id).filter(course=self.course).order_by('-id')
        if prev:
            return prev.first().slug
        return None

    course = models.ForeignKey(Course, verbose_name="Curso")
    name = models.CharField(max_length=255, verbose_name="capitulo")
    description = models.CharField(max_length=255, verbose_name="Descripción")
    slug = models.SlugField(blank=True, max_length=255)
    video_url = EmbedVideoField(verbose_name='URL de video')
    has_been_viewed = models.BooleanField(default=False)

    def __str__(self):
        return self.name

    def save(self, *args, **kwargs):
        self.slug = slugify(self.name)
        super(Chapter, self).save(*args, **kwargs)

    class Meta:
        verbose_name = "capitulo"
        verbose_name_plural = "capitulos"
John
@flyboy1565
Apr 11 2017 17:02
Is the get_next_slug providing the correct information?
This looks right to me.
I would almost need this in my hands to play with how it works.. thats the way i troubleshoot things :D
Cristian Samaniego
@chrisRubiano
Apr 11 2017 20:14
all i had to do was to change the template tags, although it makes no sense to me why it wasnt working, it does now
{% if not chapter.get_prev_slug %}
{% elif chapter.get_prev_slug %}
    <a href="{% url 'courses:chapter_details' course.slug chapter.get_prev_slug %}" class="btn btn-info my-2 pull-left"><i class="fa fa-chevron-left"></i> Capítulo anterior</a>
{% endif %}
{% if not chapter.get_next_slug %}
{% elif chapter.get_next_slug %}
    <a href="{% url 'courses:chapter_details' course.slug chapter.get_next_slug %}" class="btn btn-info my-2 pull-right">Siguiente capítulo <i class="fa fa-chevron-right"></i></a>
{% endif %}