嗨,我的Django oscar项目实现了Django oscar.我能够实现我的自定义API,我用它来查看类别并显示它们.现在API的问题是类别的子类别在我的API视图中显示为类别,我希望它们在一个数组中,表明它们是子类别.我的分类代码如下
customapi序列化器类
class CategorySerializer(serializers.ModelSerializer):
class Meta:
model = Category
fields = ('id', 'numchild', 'name', 'description', 'image', 'slug')
Run Code Online (Sandbox Code Playgroud)
查看
class CategoryList(generics.ListAPIView):
queryset = Category.objects.all()
serializer_class = CategorySerializer
class CategoryDetail(generics.RetrieveAPIView):
queryset = Category.objects.all()
serializer_class = CategorySerializer
Run Code Online (Sandbox Code Playgroud)
customapi/urls.py
url(r'^caty/$', CategoryList.as_view(), name='category-list'),
url(r'^caty/(?P<category_slug>[\w-]+(/[\w-]+)*)_(?P<pk>\d+)/$',
CategoryDetail.as_view(), name='category'),
Run Code Online (Sandbox Code Playgroud)
JSON
[
{
"id": 2,
"path": "0001",
"depth": 1,
"numchild": 4,
"name": "Clothes",
"description": "<p>Beautiful Clothes</p>",
"image": null,
"slug": "clothes"
},
{
"id": 8,
"path": "00010001",
"depth": 2,
"numchild": 0,
"name": "c",
"description": "",
"image": null,
"slug": …Run Code Online (Sandbox Code Playgroud) 我有一个javafx应用程序,用户在测试字段中输入一些细节,并在列表视图中显示.我现在有一个使用printjob打印的按钮,但每次按下打印按钮时,打印机都会打印垃圾数据,jhsjs6sh3#uhbsbkahi而不是ListView中的实际值.下面是我打印功能的代码
public void print (final Node node) {
Printer printer = Printer.getDefaultPrinter();
PageLayout pageLayout = printer.createPageLayout(Paper.A4, PageOrientation.PORTRAIT, Printer.MarginType.HARDWARE_MINIMUM);
final double scaleX = pageLayout.getPrintableWidth() / node.getBoundsInParent().getWidth();
final double scaleY = pageLayout.getPrintableHeight() / node.getBoundsInParent().getHeight();
node.getTransforms().add(new Scale(scaleX, scaleY));
PrinterJob job =PrinterJob.createPrinterJob();
if (job != null ){
boolean success = job.printPage(node);
System.out.println("printed");
if (success){
System.out.println(success);
job.endJob();
}
}
}
Run Code Online (Sandbox Code Playgroud)
@FXML
? private void printOps(ActionEvent event){? ? print(billingDataList);?
}
我使用MacBook进行开发和HP打印机.
我有一个django电子商务项目工作正常,直到我决定改进它.我让用户在某些服务上下订单,但每次下订单时都要输入他们的详细信息(姓名,邮件,地址等),所以我决定升级应用程序,以便用户可以添加他们的帐单地址,并可以参考在订单中或继续作为客人.
模型
class Order(models.Model):
first_name = models.CharField(max_length=50)
last_name = models.CharField(max_length=50)
email = models.EmailField()
address = models.CharField(max_length=250)
postal_code = models.CharField(max_length=20)
city = models.CharField(max_length=100)
created = models.DateTimeField(auto_now_add=True)
updated = models.DateTimeField(auto_now=True)
paid = models.BooleanField(default=False)
class OrderItem(models.Model):
order = models.ForeignKey(Order, related_name='items')
product = models.ForeignKey(Product,related_name='order_items')
price = models.DecimalField(max_digits=10, decimal_places=2)
quantity = models.PositiveIntegerField(default=1)
Run Code Online (Sandbox Code Playgroud)
视图
def order_create(request):
cart = Cart(request)
if request.method == 'POST':
form = OrderCreateForm(request.POST)
if form.is_valid():
order = form.save()
for item in cart:
OrderItem.objects.create(order=order, product=item['product'],price=item['price'], quantity=item['quantity'])
cart.clear()
return render(request,'order/created.html', {'order': order})
else:
form = …Run Code Online (Sandbox Code Playgroud) 我正在开发一个iOS应用程序,它使用alamofire和swiftyJSON与API进行交互.在这个api中,我得到了一堆返回的值,其中一个是图像.返回的图像以数组的形式出现,但我能够遍历数组并显示单个图像.为了使应用程序更高级,我决定在我的应用程序中实现UIPageViewController类.我调用了API函数并试图将我的图像传递给视图控制器.
我的故事板中的事物列表
据我所知,我的代码很好,但是当我运行应用程序时,控制台中没有任何反应.以下是我的代码.
protocol ProductImagesPageViewControllerDelegate: class {
func setupPageController(numberOfPages: Int)
func turnPageController(to index: Int)
}
class ProductPageVC: UIPageViewController {
weak var pageViewControllerDelegate: ProductImagesPageViewControllerDelegate?
override func viewDidLoad() {
super.viewDidLoad()
automaticallyAdjustsScrollViewInsets = false
dataSource = self
delegate = self
}
func configureImg() {
let productId = ProductServices.instance.selectedProduct?.id
ProductServices.instance.findIndividualProducts(id: productId!, completion: { (success) in
if success {
ProductServices.instance.productDetails.forEach({ (productDetail) in
let images = productDetail.productImg.count
if images > 0 {
for image in 0..<(images) {
let imageVC = self.storyboard?.instantiateViewController(withIdentifier: PRODUCT_IMAGE_VC) …Run Code Online (Sandbox Code Playgroud) 我UserNotification在我的应用程序中使用框架并发送本地通知(不是推送通知),我想将徽章设置为收到的通知数量,所以我所做的是将收到的通知数量设置为用户默认值然后我尝试将值分配给徽章以获取徽章编号,但徽章编号不会增加.这是我的代码
设置接收通知的值
center.getDeliveredNotifications { notification in
UserDefaults.standard.set(notification.count, forKey: Constants.NOTIFICATION_COUNT)
print("notification.count \(notification.count)")
print(".count noti \(UserDefaults.standard.integer(forKey: Constants.NOTIFICATION_COUNT))")
}
Run Code Online (Sandbox Code Playgroud)
这准确地打印了收到的通知数量,当我决定将其设置为我的徽章时,它只显示1
content.badge = NSNumber(value: UserDefaults.standard.integer(forKey: Constants.NOTIFICATION_COUNT))
Run Code Online (Sandbox Code Playgroud)
我不知道为什么价值不会每次都增加.任何帮助,将不胜感激.
或者,如果可以随时在应用程序中的任何位置更新徽章.
我的集群中有一个 grafana Loki 日志。我可以看到我的日志,但目前该集群已不再使用,我想删除它,但我仍然有一些日志,我想提取 Loki 并可能将其存储在我的系统本地或 Azure 上桶。
有没有办法提取此日志并保存在本地或天蓝色存储桶中。我使用 loki helm 来设置我的 Loki、promethus 任何帮助表示赞赏
我有一个申请,用户可以通过填写表格来联系我,用户只需填写他的详细信息和他的电子邮件和主题.
代码不会引发任何错误,但在设置完所有内容后我无法收到邮件,但联系人详细信息会存储在数据库中,因为我希望将其存储起来.
以下是我的代码.
Models.py
class Contact(models.Model):
name = models.CharField(max_length=100)
message = models.TextField()
sender = models.EmailField()
phone = models.CharField(max_length=10)
cc_myself = models.BooleanField(blank=True)
time = models.DateTimeField(auto_now_add=True, db_index=True)
def __str__(self):
return 'Message for {}'.format(self.sender)
Run Code Online (Sandbox Code Playgroud)
Forms.py
class ContactForm(forms.ModelForm):
class Meta:
model = Contact
fields = ['name', 'sender', 'phone', 'message', 'cc_myself']
Run Code Online (Sandbox Code Playgroud)
Views.py
def contact(request):
if request.method == 'POST':
contact_form = ContactForm(request.POST)
if contact_form.is_valid():
name = contact_form.cleaned_data['name']
message = contact_form.cleaned_data['message']
sender = contact_form.cleaned_data['sender']
phone = contact_form.cleaned_data['phone']
cc_myself = contact_form.cleaned_data['cc_myself']
recipients = ['xxxx@gmail.com'] …Run Code Online (Sandbox Code Playgroud) 我有一个 iOS 应用程序,我想将其放入 AppStore。然而,我在发展目标方面迷失了方向。我不知道是否必须将部署目标设置为 11.0 还是 10.0。大多数代码在 10.x 上运行良好。我想知道将部署目标设置为较低版本是否是一个好习惯。
我正在尝试对我的应用程序进行单元测试,大部分测试失败,原因是异步等待失败:超过 30 秒超时,未实现预期:“Home Code”。
我不知道为什么它会这样失败,但这是我下面的代码
class HomeTest: XCTestCase {
override func setUp() {
}
override func tearDown() {
}
func testHome() {
let expec = expectation(description: "Home Code")
let presenter = HomePresenter(view: HomeTestVC(expectation: expec), source: Repository.instance)
presenter.start()
wait(for: [expec], timeout: 30)
}
func testPerformanceExample() {
self.measure {
}
}
}
class HomeTestVC: HomeContract.View {
func showRatingForLastTrip(_ trip: Trip) {}
func setProgress(enabled: Bool) {}
func didFail(message: String) {}
func didShowError(error: Error) {}
func didShowStatusCode(code: Int?) {
XCTAssertGreaterThan(200, code ?? 0) …Run Code Online (Sandbox Code Playgroud) 在 helm 的 values.yaml 文件中,我试图用引号创建一个值,但是当我运行它时,它给出了不同的结果
值.yaml
annotation: '"ports": {"88":"sandbox-backendconfig"}}'
{{ .Values.annotation }}
Run Code Online (Sandbox Code Playgroud)
当我进行空运行时显示什么
"ports": {"88":"sandbox-backendconfig"}}
Run Code Online (Sandbox Code Playgroud)
我怎样才能让它周围的单引号也显示出来
swift ×4
django ×3
ios ×3
kubernetes ×2
python ×2
alamofire ×1
azure ×1
cloudkit ×1
django-oscar ×1
grafana ×1
grafana-loki ×1
java ×1
javafx ×1
json ×1
printing ×1
realm ×1
sdwebimage ×1
sendmail ×1
unit-testing ×1
yaml ×1