最近我在django模型中添加了OneToOneField,我在此字段中将None设置为默认值.然后我收到了这个错误:
django.db.utils.IntegrityError: NOT NULL constraint failed: user_myuser.album_id
型号:
class MyUser(models.Model):
username = models.CharField(unique=True, max_length=25)
first_name = models.CharField(max_length=50, default='')
last_name = models.CharField(max_length=70, default='')
register_date = models.DateTimeField(default=timezone.now)
update_at = models.DateTimeField(auto_now=True)
# the default value problem is here
album = models.OneToOneField(Album, auto_created=True,
on_delete=models.CASCADE, default=None)
Run Code Online (Sandbox Code Playgroud)
这是专辑模型:
class Album(models.Model):
name = models.CharField(max_length=100, null=True)
author = models.CharField(max_length=100, null=True)
picture_address = models.ImageField(upload_to=album_upload_destination, null=True)
creation_year = models.IntegerField(default=-1)
rate = models.IntegerField(default=0)
timestamp = models.DateTimeField(auto_now_add=True)
Run Code Online (Sandbox Code Playgroud) 我看到了类似的问题,但没有一个解决了我的问题。
我有一个像这样的简单模板标签:
@register.simple_tag
def liked_by_user(post_id, user):
try:
PostModel.objects.get(pk=post_id).like_set.get(user=user)
return True
except:
return False
Run Code Online (Sandbox Code Playgroud)
我想在这样的 if 语句中使用它:
{% if liked_by_user post.pk request.user %}
doing somethin...
{% else %}
doing somethin...
{% endif %}
Run Code Online (Sandbox Code Playgroud)
我能做什么 ?
我RecyclerViews在LinearLayout里面有2 个ScrollView:
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="@dimen/few_value">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<com.foodjoo.fjco.customViews.BYekanFontText
android:id="@+id/market_category"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:padding="@dimen/normal_plus_value"
android:text=" ?????? > ????? ???? ??? "
android:textAppearance="@style/Base.TextAppearance.AppCompat.Subhead"
android:textColor="@color/light_black2" />
<android.support.v7.widget.RecyclerView
android:id="@+id/market_cat_recycler"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<com.foodjoo.fjco.customViews.BYekanFontText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:padding="@dimen/normal_plus_value"
android:text="????? ???"
android:textAppearance="@style/Base.TextAppearance.AppCompat.Subhead"
android:textColor="@color/light_black2" />
<android.support.v7.widget.RecyclerView
android:id="@+id/market_hours_recycler"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
</ScrollView>
Run Code Online (Sandbox Code Playgroud)
两个回收商都有nestedScrollEnabledfla.
问题在于:当渲染布局时,第一个recyclerView将填充,屏幕底部的第二个recyclerView将不会显示所有项目,因为第一个高度!! 但它应该滚动,因为它们都在scrollView !!
所以有什么问题 ?
android android-layout android-recyclerview nestedrecyclerview
我正在创建一个recyclerViewandroid 项目,我想gridLayout manager在我的recyclerView.
这是我的代码:
workHourRecycler = view.findViewById(R.id.market_hours_recycler);
workHourRecycler.setLayoutManager(new GridLayoutManager(getContext(),4));
Run Code Online (Sandbox Code Playgroud)
但GridLayout一定'rtl direction'有人知道吗?
谢谢。
android android-layout android-recyclerview recyclerview-layout
我使用主管在系统启动时运行 django websocket。
当我启动主管时,它会引发
ModuleNotFoundError:没有名为“django”的模块
在日志文件中。
这是主管conf:
[fcgi-program:myProject]
environment=HOME="/home/ubuntu/envFiles/myProject/bin"
# TCP socket used by Nginx backend upstream
socket=tcp://0.0.0.0:8000
directory=/home/ubuntu/projects/myProject
command=daphne -u /run/daphne/daphne%(process_num)d.sock --fd 0 --access-log - --proxy-headers myProject.asgi:application
# Number of processes to startup, roughly the number of CPUs you have
numprocs=4
process_name=asgi%(process_num)d
autostart=true
autorestart=true
stdout_logfile=/home/ubuntu/logs/project.log
redirect_stderr=true
Run Code Online (Sandbox Code Playgroud)
当我尝试通过 重新启动主管时supervisorctl restart all,它再次出现导入模块错误。
错误日志:
ModuleNotFoundError:没有名为“django”的模块
我认为它使用系统 python 路径但我environment在配置文件中定义,所以主管必须使用那里的环境。
有什么问题 ?
如何在主管 conf 中设置我的 django 环境文件?