jira curl得到问题(jira curl to get issues)
我试图使用curl在jira服务器中获取数据。 我试过这个命令
curl -u username:password -X GET -H "Content-Type: application/json" jiraServer/rest/api/2/search?jql=created >= "2015-11-18"
它在curl目录下载了一个文件,文件说明了
{“errorMessages”:[“JQL查询中的错误:查询结束前的Expecting运算符。有效运算符为'=','!=','<','>','<=','> =','〜','!〜','IN','NOT IN','IS'和'IS NOT'。“],”错误“:{}}
我尝试将创建的> =“2015-11-18”放在Jira Web界面的高级搜索中,它可以工作。 不要为什么卷曲失败?
I am trying to get data in jira server using curl. I tried this command
curl -u username:password -X GET -H "Content-Type: application/json" jiraServer/rest/api/2/search?jql=created >= "2015-11-18"
It downloaded a file in the curl directory and the file says
{"errorMessages":["Error in the JQL Query: Expecting operator before the end of the query. The valid operators are '=', '!=', '<', '>', '<=', '>=', '~', '!~', 'IN', 'NOT IN', 'IS' and 'IS NOT'."],"errors":{}}
I tried put the created >= "2015-11-18" in advanced search in Jira web interface and it works. Don't why it failed in curl?
原文:https://stackoverflow.com/questions/33780543
最满意答案
仅供参考
假设您有三个模型:
class User(model.Model): username = model.CharField('username', max_length=10) class Question(model.Model): title = models.CharField('title', max_length=10) class Answer(model.Model): user = model.ForeignKey(User) question = model.ForeignKey(Question) body = model.TextField('the answer body')
你需要序列化
Answer
,显示Question
的详细信息,但不显示User
的详细信息,然后你可以定义你的序列化服务器:class QuestionSerializer(serializers.ModelSerializer): class Meta: model = Question exclude = [] class AnswerSerializer(serializers.ModelSerializer): question = QuestionSerializer(many=False, read_only=True) class Meta: model = Answer exclude = []
当您使用
AnswerSerializer
序列化Answer
时,您会注意到question
字段同时是序列化的,但是user
字段仍然是没有序列化的整数。如果需要序列化外键,可以显式定义序列化程序中的字段,字段名称等于
model
的字段名称,该值等于外键模型序列化程序。 当模型序列化时,在这种情况下Answer
,外键字段,本案例的question
,将用QuestionSerializer
“扩展”,而其他外键字段仍然保留原始外键值,在这种情况下是user
,如果你没有在序列化器中明确定义了一个序列化器字段。希望它会有所帮助。
Just for your reference
Suppose you have three models:
class User(model.Model): username = model.CharField('username', max_length=10) class Question(model.Model): title = models.CharField('title', max_length=10) class Answer(model.Model): user = model.ForeignKey(User) question = model.ForeignKey(Question) body = model.TextField('the answer body')
And you need to serialise
Answer
, with showing the detail ofQuestion
, but not showing the detail ofUser
, then you could define your serialisers like that:class QuestionSerializer(serializers.ModelSerializer): class Meta: model = Question exclude = [] class AnswerSerializer(serializers.ModelSerializer): question = QuestionSerializer(many=False, read_only=True) class Meta: model = Answer exclude = []
when you serialise
Answer
withAnswerSerializer
, you will notice thatquestion
field is serialise at the same time, howeveruser
field is still an integer without serialising.If you need to serialise a foreign key, you can define a field in the serializer explicitly, and the field name equal to the field name in
model
, and the value is equal to Foreign key model serializer. When the model is serialise,Answer
in this case, the foreign key field,question
for this case, will be "expanded" withQuestionSerializer
, and other foreign key fields still keep the origin foreign key value,user
in this case, if you haven't explicitly defined a serializer field in the serializer.Hope it would help.
相关问答
更多-
当你把所有的函数序列化器都设置为1时,这很复杂,我会在这种情况下创建一个UserCreateSerializer : class UserCreateSerializer(serializers.ModelSerializer): """A serializer for our user profile objects.""" class Meta: model = models.User extra_kwargs = {'password': {'writ ...
-
如果您使用的是ModelViewSet ,只需将put添加到您的url的as_view()参数中。 您的网址应该包含以下内容: TaskViewSet.asView({'get': 'retrieve', 'put': 'update'}) 即: url(r'^your-regex$', TaskViewSet.asView({'get': 'retrieve', 'put': 'update'}), name='whatever') 然后,您可以使用requests.put来更新它。 如果您想覆盖更新 ...
-
不,不是在你的models.py - 在模型方面的事情,所有你需要做的是在你的INSTALLED_APPS包含适当的应用程序( rest_framework.authtoken )。 这将提供与用户外键的令牌模型。 您需要做的是决定何时以及如何创建这些令牌对象。 在您的应用程序中,每个用户是否自动获取令牌? 还是只有某些授权用户? 或者只有当他们特别要求一个? 如果每个用户都应该有一个令牌,那么您链接到的页面上会显示一段代码,它会显示如何设置信号以自动创建它们: @receiver(post_save, s ...
-
Django Rest框架序列化程序排除深度为2的外键(Django Rest framework serializer exclude foreign key with depth 2)[2022-06-12]
啊,我刚刚发现它: 我需要在资源中添加我想要显示什么资源的所有字段.... fields =('name',(“parent”,“MyObjectResource”),'以及你想看到的所有其他字段......') 我在这里找到它: 谷歌组论坛问题 你可以跳过exlude,忽略它,只需添加你想要显示的字段,你不必定义它们,除非你需要指出使用什么资源。 所以以下是resource.py部分的最终代码: class MyObjectResource(ModelResource): model = MyOb ... -
您可以为此使用PrimaryKeyRelatedField 。 首先将related_name属性设置为您的外键。 university = models.ForeignKey(University, related_name='students') 然后像这样更改序列化程序。 class UniversitySerializer(serializers.ModelSerializer): students = serializers.PrimaryKeyRelatedField(many=Tru ...
-
使用CreateOnlyDefault ,该值仅用于创建而不用于更新。 例如: class MySerializer: created = serializers.DateTimeField( read_only=True, default=serializers.CreateOnlyDefault(timezone.now) ) modified = serializers.DateTimeField( read_only=True, ...
-
Django Rest Framework获取API中显示的多对多关系(Django Rest Framework get many-to-many relation showing in API)[2022-06-14]
您的Episode模型与您的Guest或Topic模型没有任何转发关系。 出于这个原因,你的Episode序列化程序应该设法序列化guest_set和topic_set而不是guest和topic 。 如果您为这些M2M字段指定相关名称,则可以在此处自定义命名约定。 现在你有这个: class Guest(models.Model): episodes = models.ManyToManyField(Episode) ... 这意味着要获得所有与给定Episode名为ep的Guests ... -
如何在Django Rest Framework中显示单个字段的深度?(How to show depth of a single field in Django Rest Framework?)[2023-01-27]
仅供参考 假设您有三个模型: class User(model.Model): username = model.CharField('username', max_length=10) class Question(model.Model): title = models.CharField('title', max_length=10) class Answer(model.Model): user = model.ForeignKey(User) question ... -
如何在django rest框架查询中获得单个字段?(How to get single field as result in django rest framework query?)[2022-03-11]
那么你想过滤你的模型结果吗? 如果是这样,看起来你需要创建一个APIView,获取你的模型,然后操纵你想要显示的字段。 像这样的东西: class UserField(APIView): def get(self, request): path = str.split(str(request.path),'/') print(path) fieldname = path[4] #check your path on the print ... -
Django Rest Framework中Foreignkey字段的动态选择(Dynamic choices in Foreignkey Field in Django Rest Framework)[2021-10-09]
我想你正在寻找这部分 DRF文档。 基本上,使用您的Django模型自己的表示。 例如,在您的Student模型中,您可以添加__str__方法: # this is for Python 3, use __unicode__ on Python 2 def __str__(self): return self.name Django的元选项文档在这里 ,寻找模型方法 。 I think you're looking for this part of the DRF docum ...