Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Jul 14 2021 16:11
    @MadLittleMods banned @Rehmanjeff
Fabian Schlager
@ghtyrant

I have some issues with Django migrations, and I'm not sure if it's intended behaviour or a bug. I have two migrations, one adds a new permission to a model, the next runs Python code to look up a group and gives that new permission to this group:

class Migration(migrations.Migration):

    dependencies = [
        ("gallery", "0023_gallerypermissions"),
    ]

    operations = [
        migrations.AlterModelOptions(
            name="gallerypermissions",
            options={
                "default_permissions": (),
                "managed": False,
                "permissions": (
                   (
                        "manage_reference_shots",
                        "Manually upload and remove reference shots.",
                    ),
                ),
            },
        ),
    ]
def add_permission(apps, schema_editor):
    Group = apps.get_model("auth", "Group")
    Permission = apps.get_model("auth", "Permission")

    group = Group.objects.get(name="Regular")
    group.permissions.add(Permission.objects.get(codename="manage_reference_shots"))
    group.save()


def remove_permission(apps, schema_editor):
    Group = apps.get_model("auth", "Group")
    Permission = apps.get_model("auth", "Permission")

    group = Group.objects.get(name="Regular")
    group.permissions.remove(Permission.objects.get(codename="manage_reference_shots"))
    group.save()


class Migration(migrations.Migration):

    dependencies = [
        ("gallery", "0024_auto_20200226_1059"),
    ]

    operations = [migrations.RunPython(add_permission, reverse_code=remove_permission)]

Now, if I run those migrations separately, all works well. If I simply run migrate, it fails due to the second migration not being able to find manage_reference_shots in the database. I kinda understand this, as all migrations run in the same transaction (is there a way to run them in separate transactions, without doing so manually from the command line?).
What I don't understand is: The first migration is marked as done, even though the permission is NOT in the database afterwards!

Bo
@BoPeng

@leqnam Not really. I am doing something like

def get_queryset(self):
    books = Book.objects.filter(by self.kwargs['user'])
    return [x.id for x in books if is_latest_version(x, books)]

with the risk of fellow workers calling get_queryset().filter() later so I am still hoping for a SQL/ORM solution, or something like return QuerySet(instance_list) that can be filtered upon.

Rian0702
@Rian0702

Hello everyone,
is it possible to run something like a cron job when a model is saved? And to stop that too?

The goal is:

  • User enters something like "start" in table_1
  • a value in table_2 updates every 5 minutes
  • User enters something like "stop" in table_1
  • updating the table_2 stops

is that even possible with django? I read about celery but this has to be triggered by a command line if i did not get this wrong

Ghost
@ghost~5e554ddcd73408ce4fdab57a
you can do more with pytonik MVC framework join the community https://gitter.im/pytonik-mvc/community
ganboldoo7
@ganboldoo7
Hi guys, I have a question about database column indexing.
What is the difference between db_index=True and Meta.Indexes ?
Ghost
@ghost~5e554ddcd73408ce4fdab57a
Pytonik Alpha Version 1.9.8a2 has been released out for testing, start deploying, contributing to pytonik Framework. Download and install https://pypi.org/project/pytonik/1.9.8a2/ It will Bleed your mind. star and forked https://github.com/pytonik/pytonik/
Bo
@BoPeng
What apps do you guys use for general "invitation", "review" and "approve" emails, for example for users to send content (a link) for another user to review, approve and deny? django-invitations seems to the app to use but it is in beta and there should be more stable apps for such a common feature.
QbasicFan
@QbasicFan
@BoPeng django-invitations looks solid with more than 230 starts...But looks like you will have to do some customization to send emails based on different states and privileges ...
Ghost
@ghost~5e554ddcd73408ce4fdab57a
Pytonik Alpha Version 1.9.8a2 has been released out for testing, start deploying, contributing to pytonik Framework. Download and install https://pypi.org/project/pytonik/1.9.8a2/ It will Bleed your mind. star and forked https://github.com/pytonik/pytonik/
Bo
@BoPeng
@QbasicFan Thanks. I will give django-invitations a try. I have seen such features from django apps developed before django-invitations was developed so I thought there must be some app out there that is more mature than django-invitations (beta + 63% code coverage).
Bo
@BoPeng
@QbasicFan django-invitations is actually not usable because it is designed for inviting others to join a site. Its model has only one link so I cannot even use it for two actions ("reject" and "approve"). I will continue to search for something more general.
QbasicFan
@QbasicFan
you can probably build a quick solution to send invites based on the requirements you want...
If you do make it open source, I would like to use it and contribute
Bo
@BoPeng
@QbasicFan I found django-generic-confirmation a good fit for my need, as long as it supports confirmation from another user (not sure yet). I do not understand why this app did not receive much attention though (2 watcher + 18 stars) because its concept is very general and can be applied to a lot of cases. What this app is lacking is 1) django 2.x support (there is a PR for it), 2) more doc + support (seeming no longer maintained now), 3) functions to send emails and reminding emails. I think, if there is no other good option available, I will have to fork this app to add django 2.x 3.x support, and email support (e.g. tables from django-email-confirmation), and I might have to rename it (e.g. django-deferred-form so that it can be released and used in my application (right now I have to install git to use its github version).
QbasicFan
@QbasicFan
thanks for sharing
Bo
@BoPeng
But I still think there should be existing solutions for it, and it will not be a waste of time to evaluate more possibilities. For example, my project uses celery so I can potentially add all "pending" actions to the celery queue but not execute, and allow the notification receiver to start the task through a link from an email.
Bo
@BoPeng
Or add all the possible actions to a customized table and let django-email-confirm-la confirms them. The last commit for this package is 3 years ago and it does not support django 2.x though.
El 李天宝
@elcolie
I am wonder. Why I don't find any AWS Cognitos tools that make migration files?
I am fully understand that it is not a Postgresql or local db. But why?
James Komo
@jameskomo
Who has used Django AutoComplete light especially working with two models (FK)
Nitish Kumar
@thisisnitish
from django.shortcuts import render
from django.views.generic import ListView
from .models import Post
#from django.http import HttpResponse


def home(request):
    context = {
        'posts' : Post.objects.all()
    }
    return render(request, 'blog/home.html', context)


def PostListView(ListView):
    model = Post
    template_name = 'blog/home.html'   # <app>/<model>_<viewtype>.html
    context_object_name = 'posts'
    ordering = ['-date_posted']


def about(request):
    return render(request, 'blog/about.html', {'title' : 'About'})
from django.urls import path
from .views import PostListView
from . import views

urlpatterns = [
    path('', PostListView.as_view(), name = 'blog-home'),
    path('about/', views.about, name = 'blog-about'),
]
    path('', PostListView.as_view(), name = 'blog-home'),
AttributeError: 'function' object has no attribute 'as_view'
can anybody help me...
I'm getting error...I tried but couldn't find the solution
AlbertDavid
@AlbertDavid94
you're defining a function PostListView whereas that should be a class.
ListView is not being used as a inheritance object but as a bare arguement for your function
Nitish Kumar
@thisisnitish
ohh..thankyou @AlbertDavid94 thanks a lot... 😊
Nitish Kumar
@thisisnitish
from django.shortcuts import render, redirect
from django.contrib import messages
from django.contrib.auth.decorators import login_required
from .forms import UserRegisterForm, UserUpdateForm, ProfileUpdateForm

def register(request):
    if request.method == 'POST':
        form = UserRegisterForm(request.POST)
        if form.is_valid():
            form.save()
            username = form.cleaned_data.get('username')
            messages.success(request, f'Your account has been created! You are now able to log in')
            return redirect('login')
    else:
        form = UserRegisterForm()
    return render(request, 'users/register.html', {'form': form})


@login_required
def profile(request):
    if request.method == 'POST':
        u_form = UserUpdateForm(request.POST, instance= request.user)
        p_form = ProfileUpdateForm(request.POST, request.FILES, instance= request.user.profile)

        if u_form.is_valid() and p_form.is_valid():
            u_form.save()
            p_form.save()
            messages.success(request, f'Your account has been updated!!')
            return redirect('profile')
    else:
        u_form = UserUpdateForm(instance= request.user)
        p_form = ProfileUpdateForm(instance= request.user.profile)

    context = {
        'u_form': u_form,
        'p_form': p_form
    }

    return render(request, 'users/profile.html', context)
TypeError: save() got an unexpected keyword argument 'force_insert'
I'm getting this error whenever I'm registering the new user...can anybody help me
TypeError at /register/
save() got an unexpected keyword argument 'force_insert'
this one is on the web page
Nitish Kumar
@thisisnitish
@AlbertDavid94 can you solve my problem
Saket Patel
@Samy-33
Hey guys, have any of you guys use CI/CD to deploy django app on Google App Engine?
I am not sure how I should handle ./manage.py migrate in CD
Any help is appreciated
Roel
@roelzkie15
@Samy-33 you can use fabric for your deployment automation
Saket Patel
@Samy-33
Hi @roelzkie15, App Engine doesn't allow running commands over ssh
Vishesh Mangla
@Teut2711
What are best practices to read data and add to database?
should I do it in views?
I want to make a site with links to my ds algo solved problems.
So I want to read all the file names and show it as html.
as a tag
If user clicks he can then see the code
is importing os and reading name of files done in views?
how to I use models in this following context
?
Hanny Goodwin
@hannylicious
If you read through the documentation, you can find a ton of great information which shows how to read data and add data to the database (Forms, most likely if it’s user input)
Ghost
@ghost~5e554ddcd73408ce4fdab57a
New beta/release candidate 1.9.8 is out for deployment. https://github.com/pytonik/pytonik install: https://pypi.org/project/pytonik/1.9.8rc1/
Nitish Kumar
@thisisnitish
Screenshot 2020-03-11 at 7.51.05 PM.png
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_PORT = 587
EMAIL_USE_TLS = True
EMAIL_HOST_USER = os.environ.get('EMAIL_USER')
EMAIL_HOST_PASSWORD = os.environ.get('EMAIL_PASS')